This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new bcc79ecda6 Restore only creating Stream input buffer when required
bcc79ecda6 is described below
commit bcc79ecda60e8d704323f40fe090c09135607ac7
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Jul 23 12:35:11 2024 +0100
Restore only creating Stream input buffer when required
---
.../apache/coyote/http2/AbstractNonZeroStream.java | 15 +++++++++++-
.../apache/coyote/http2/Http2UpgradeHandler.java | 2 +-
java/org/apache/coyote/http2/RecycledStream.java | 2 +-
java/org/apache/coyote/http2/Stream.java | 28 ++++++++++++++++------
webapps/docs/changelog.xml | 8 +++++++
5 files changed, 45 insertions(+), 10 deletions(-)
diff --git a/java/org/apache/coyote/http2/AbstractNonZeroStream.java
b/java/org/apache/coyote/http2/AbstractNonZeroStream.java
index 406a112caa..6dc7c19077 100644
--- a/java/org/apache/coyote/http2/AbstractNonZeroStream.java
+++ b/java/org/apache/coyote/http2/AbstractNonZeroStream.java
@@ -61,13 +61,26 @@ abstract class AbstractNonZeroStream extends AbstractStream
{
}
+ /**
+ * Obtain the ByteBuffer to store DATA frame payload data for this stream
that has been received from the client.
+ *
+ * @return {@code null} if the DATA frame payload can be swallowed, or a
ByteBuffer with at least enough space
+ * remaining for the current flow control window for stream
data from the client.
+ *
+ * @deprecated Unused. Will be removed in Tomcat 11.
+ */
+ @Deprecated
+ ByteBuffer getInputByteBuffer() {
+ return getInputByteBuffer(true);
+ }
+
/**
* Obtain the ByteBuffer to store DATA frame payload data for this stream
that has been received from the client.
*
* @return {@code null} if the DATA frame payload can be swallowed, or a
ByteBuffer with at least enough space
* remaining for the current flow control window for stream
data from the client.
*/
- abstract ByteBuffer getInputByteBuffer();
+ abstract ByteBuffer getInputByteBuffer(boolean create);
/**
* Notify that some data has been received.
diff --git a/java/org/apache/coyote/http2/Http2UpgradeHandler.java
b/java/org/apache/coyote/http2/Http2UpgradeHandler.java
index f0a245a48c..dac521ef19 100644
--- a/java/org/apache/coyote/http2/Http2UpgradeHandler.java
+++ b/java/org/apache/coyote/http2/Http2UpgradeHandler.java
@@ -1549,7 +1549,7 @@ class Http2UpgradeHandler extends AbstractStream
implements InternalHttpUpgradeH
AbstractNonZeroStream abstractNonZeroStream =
getAbstractNonZeroStream(streamId, true);
abstractNonZeroStream.checkState(FrameType.DATA);
abstractNonZeroStream.receivedData(payloadSize);
- ByteBuffer result = abstractNonZeroStream.getInputByteBuffer();
+ ByteBuffer result = abstractNonZeroStream.getInputByteBuffer(true);
if (log.isTraceEnabled()) {
log.trace(sm.getString("upgradeHandler.startRequestBodyFrame.result",
getConnectionId(),
diff --git a/java/org/apache/coyote/http2/RecycledStream.java
b/java/org/apache/coyote/http2/RecycledStream.java
index c4c180ac1f..fc689f7c2a 100644
--- a/java/org/apache/coyote/http2/RecycledStream.java
+++ b/java/org/apache/coyote/http2/RecycledStream.java
@@ -59,7 +59,7 @@ class RecycledStream extends AbstractNonZeroStream {
* payload than the remaining flow control window is received for this
recycled stream.
*/
@Override
- ByteBuffer getInputByteBuffer() {
+ ByteBuffer getInputByteBuffer(boolean create) {
if (remainingFlowControlWindow < 0) {
return ZERO_LENGTH_BYTEBUFFER;
} else {
diff --git a/java/org/apache/coyote/http2/Stream.java
b/java/org/apache/coyote/http2/Stream.java
index d6ace73a15..e24297985d 100644
--- a/java/org/apache/coyote/http2/Stream.java
+++ b/java/org/apache/coyote/http2/Stream.java
@@ -628,8 +628,8 @@ class Stream extends AbstractNonZeroStream implements
HeaderEmitter {
@Override
- final ByteBuffer getInputByteBuffer() {
- return inputBuffer.getInBuffer();
+ final ByteBuffer getInputByteBuffer(boolean create) {
+ return inputBuffer.getInBuffer(create);
}
@@ -790,7 +790,7 @@ class Stream extends AbstractNonZeroStream implements
HeaderEmitter {
}
int remaining;
// May be null if stream was closed before any DATA frames were
processed.
- ByteBuffer inputByteBuffer = getInputByteBuffer();
+ ByteBuffer inputByteBuffer = getInputByteBuffer(false);
if (inputByteBuffer == null) {
remaining = 0;
} else {
@@ -1173,7 +1173,19 @@ class Stream extends AbstractNonZeroStream implements
HeaderEmitter {
abstract void notifyEof();
- abstract ByteBuffer getInBuffer();
+ /**
+ * Return, creating if necessary, the input buffer.
+ *
+ * @return The input buffer
+ *
+ * @deprecated Unused. Will be removed in Tomcat 11.
+ */
+ @Deprecated
+ ByteBuffer getInBuffer() {
+ return getInBuffer(true);
+ }
+
+ abstract ByteBuffer getInBuffer(boolean create);
abstract void onDataAvailable() throws IOException;
@@ -1384,8 +1396,10 @@ class Stream extends AbstractNonZeroStream implements
HeaderEmitter {
@Override
- final ByteBuffer getInBuffer() {
- ensureBuffersExist();
+ final ByteBuffer getInBuffer(boolean create) {
+ if (create) {
+ ensureBuffersExist();
+ }
return inBuffer;
}
@@ -1512,7 +1526,7 @@ class Stream extends AbstractNonZeroStream implements
HeaderEmitter {
}
@Override
- ByteBuffer getInBuffer() {
+ ByteBuffer getInBuffer(boolean create) {
return null;
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 6cdf5c2209..3a6fa24740 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -123,6 +123,14 @@
</fix>
</changelog>
</subsection>
+ <subsection name="Coyote">
+ <changelog>
+ <fix>
+ Ensure that HTTP/2 stream input buffers are only created when there is
a
+ request body to be read. (markt)
+ </fix>
+ </changelog>
+ </subsection>
<subsection name="jdbc-pool">
<changelog>
<fix>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]