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 93c0086143 Improve the HTTP/2 stream prioritisation process.
93c0086143 is described below

commit 93c00861431466c84a69caff2b002a6dfc92d206
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 64796a75fb..1ba0001709 100644
--- a/java/org/apache/coyote/http2/Http2UpgradeHandler.java
+++ b/java/org/apache/coyote/http2/Http2UpgradeHandler.java
@@ -924,9 +924,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 {
@@ -940,19 +945,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 7d6135a9d0..746eb7b907 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -128,6 +128,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

Reply via email to