This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 28dc9f42b1 Restore only creating Stream input buffer when required
28dc9f42b1 is described below
commit 28dc9f42b1210a2cbeeff55ed89382558c0207a4
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 | 4 ++++
5 files changed, 41 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 312a9eb7e4..e2b2d90d16 100644
--- a/java/org/apache/coyote/http2/Http2UpgradeHandler.java
+++ b/java/org/apache/coyote/http2/Http2UpgradeHandler.java
@@ -1546,7 +1546,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 227d586b9e..5cc812f3f2 100644
--- a/java/org/apache/coyote/http2/Stream.java
+++ b/java/org/apache/coyote/http2/Stream.java
@@ -626,8 +626,8 @@ class Stream extends AbstractNonZeroStream implements
HeaderEmitter {
@Override
- final ByteBuffer getInputByteBuffer() {
- return inputBuffer.getInBuffer();
+ final ByteBuffer getInputByteBuffer(boolean create) {
+ return inputBuffer.getInBuffer(create);
}
@@ -788,7 +788,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 {
@@ -1171,7 +1171,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;
@@ -1382,8 +1394,10 @@ class Stream extends AbstractNonZeroStream implements
HeaderEmitter {
@Override
- final ByteBuffer getInBuffer() {
- ensureBuffersExist();
+ final ByteBuffer getInBuffer(boolean create) {
+ if (create) {
+ ensureBuffersExist();
+ }
return inBuffer;
}
@@ -1510,7 +1524,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 467639c60c..7e2e343212 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -132,6 +132,10 @@
listener on the <code>Server</code> element when using Java 22
or later. (remm)
</add>
+ <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">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]