This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push: new 834eb5a1c9 Improve the HTTP/2 stream prioritisation process. 834eb5a1c9 is described below commit 834eb5a1c996a340159d150810a4b25c9f73dd11 Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Mar 7 12:45:30 2024 -0500 Improve the HTTP/2 stream prioritisation process. If a stream uses all of the connection windows and still has content to write, it will now be added to the backlog immediately rather than waiting until the write attempt for the remaining content. Addresses intermittent test failures in the HTTP/2 RFC 9218 test --- .../apache/coyote/http2/Http2UpgradeHandler.java | 29 +++++++++++++++++++--- webapps/docs/changelog.xml | 6 +++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/java/org/apache/coyote/http2/Http2UpgradeHandler.java b/java/org/apache/coyote/http2/Http2UpgradeHandler.java index 7686ae057b..728edc6c2f 100644 --- a/java/org/apache/coyote/http2/Http2UpgradeHandler.java +++ b/java/org/apache/coyote/http2/Http2UpgradeHandler.java @@ -920,9 +920,14 @@ class Http2UpgradeHandler extends AbstractStream implements InternalHttpUpgradeH } + /* + * Requesting an allocation from the connection window for the specified stream. + */ int reserveWindowSize(Stream stream, int reservation, boolean block) throws IOException { - // Need to be holding the stream lock so releaseBacklog() can't notify - // this thread until after this thread enters wait() + /* + * Need to be holding the stream lock so releaseBacklog() can't notify this thread until after this thread + * enters wait(). + */ int allocation = 0; stream.windowAllocationLock.lock(); try { @@ -936,19 +941,35 @@ class Http2UpgradeHandler extends AbstractStream implements InternalHttpUpgradeH } long windowSize = getWindowSize(); if (stream.getConnectionAllocationMade() > 0) { + // The stream is/was in the backlog and has been granted an allocation - use it. allocation = stream.getConnectionAllocationMade(); stream.setConnectionAllocationMade(0); } else if (windowSize < 1) { - // Has this stream been granted an allocation - if (stream.getConnectionAllocationMade() == 0) { + /* + * The connection window has no capacity. If the stream has not been granted an allocation, and the + * stream was not already added to the backlog due to an partial reservation (see next else if + * block) add it to the backlog so it can obtain an allocation when capacity is available. + */ + if (stream.getConnectionAllocationMade() == 0 && stream.getConnectionAllocationRequested() == 0) { stream.setConnectionAllocationRequested(reservation); backLogSize += reservation; backLogStreams.add(stream); } } else if (windowSize < reservation) { + /* + * The connection window has some capacity but not enough to fill this reservation. Allocate what + * capacity is available and add the stream to the backlog so it can obtain a further allocation + * when capacity is available. + */ allocation = (int) windowSize; decrementWindowSize(allocation); + int reservationRemaining = reservation - allocation; + stream.setConnectionAllocationRequested(reservationRemaining); + backLogSize += reservationRemaining; + backLogStreams.add(stream); + } else { + // The connection window has sufficient capacity for this reservation. Allocate the full amount. allocation = reservation; decrementWindowSize(allocation); } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index e79a1d705b..3476cffa2e 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -119,6 +119,12 @@ FORM authentication, ensure that neither the URI, the query string nor the protocol are corrupted when restoring the request body. (markt) </fix> + <fix> + Improve the HTTP/2 stream prioritisation process. If a stream uses all + of the connection windows and still has content to write, it will now be + added to the backlog immediately rather than waiting until the write + attempt for the remaining content. (markt) + </fix> </changelog> </subsection> <subsection name="Jasper"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org