This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new d5305cafae Restore only creating Stream input buffer when required d5305cafae is described below commit d5305cafae44e206d6db05ff9337a71be96adbb4 Author: Mark Thomas <ma...@apache.org> 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 fc7556711a..f5724e3166 100644 --- a/java/org/apache/coyote/http2/Http2UpgradeHandler.java +++ b/java/org/apache/coyote/http2/Http2UpgradeHandler.java @@ -1488,7 +1488,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 bf415b74d9..0d649f8bfa 100644 --- a/java/org/apache/coyote/http2/Stream.java +++ b/java/org/apache/coyote/http2/Stream.java @@ -621,8 +621,8 @@ class Stream extends AbstractNonZeroStream implements HeaderEmitter { @Override - final ByteBuffer getInputByteBuffer() { - return inputBuffer.getInBuffer(); + final ByteBuffer getInputByteBuffer(boolean create) { + return inputBuffer.getInBuffer(create); } @@ -778,7 +778,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 { @@ -1087,7 +1087,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; @@ -1297,8 +1309,10 @@ class Stream extends AbstractNonZeroStream implements HeaderEmitter { @Override - final ByteBuffer getInBuffer() { - ensureBuffersExist(); + final ByteBuffer getInBuffer(boolean create) { + if (create) { + ensureBuffersExist(); + } return inBuffer; } @@ -1425,7 +1439,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 54896d2474..26b47b83a7 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -141,6 +141,10 @@ Add FFM compatibility methods for BoringSSL support. Renegotiation is not supported in many cases. (remm) </update> + <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: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org