You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2022/09/30 18:54:42 UTC

[tomcat] branch 10.0.x updated: BZ 66281 - unexpected timeouts when using HTTP/2 and NIO2

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 10.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.0.x by this push:
     new 5de2da1232 BZ 66281 - unexpected timeouts when using HTTP/2 and NIO2
5de2da1232 is described below

commit 5de2da123206e76e2e3c13199811f544721307a1
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Sep 30 18:17:14 2022 +0100

    BZ 66281 - unexpected timeouts when using HTTP/2 and NIO2
    
    Tiemouts may appear as client disconnections
    https://bz.apache.org/bugzilla/show_bug.cgi?id=66281
---
 java/org/apache/coyote/http2/Http2UpgradeHandler.java | 18 ++++++++++++++----
 webapps/docs/changelog.xml                            |  4 ++++
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/java/org/apache/coyote/http2/Http2UpgradeHandler.java b/java/org/apache/coyote/http2/Http2UpgradeHandler.java
index 602fa0232c..549594354d 100644
--- a/java/org/apache/coyote/http2/Http2UpgradeHandler.java
+++ b/java/org/apache/coyote/http2/Http2UpgradeHandler.java
@@ -265,6 +265,10 @@ class Http2UpgradeHandler extends AbstractStream implements InternalHttpUpgradeH
             log.debug(sm.getString("upgradeHandler.prefaceReceived", connectionId));
         }
 
+        // Allow streams and connection to determine timeouts
+        socketWrapper.setReadTimeout(-1);
+        socketWrapper.setWriteTimeout(-1);
+
         processConnection(webConnection, stream);
     }
 
@@ -343,10 +347,7 @@ class Http2UpgradeHandler extends AbstractStream implements InternalHttpUpgradeH
                     }
                 }
                 try {
-                    // There is data to read so use the read timeout while
-                    // reading frames ...
-                    socketWrapper.setReadTimeout(protocol.getReadTimeout());
-                    // ... and disable the connection timeout
+                    // Disable the connection timeout while frames are processed
                     setConnectionTimeout(-1);
                     while (true) {
                         try {
@@ -1504,6 +1505,15 @@ class Http2UpgradeHandler extends AbstractStream implements InternalHttpUpgradeH
         int thisRead = 0;
 
         while (len > 0) {
+            // Blocking reads use the protocol level read timeout. Non-blocking
+            // reads do not timeout. The intention is that once a frame has
+            // started to be read, the read timeout applies until it is
+            // completely read.
+            if (nextReadBlock) {
+                socketWrapper.setReadTimeout(protocol.getReadTimeout());
+            } else {
+                socketWrapper.setReadTimeout(-1);
+            }
             thisRead = socketWrapper.read(nextReadBlock, data, pos, len);
             if (thisRead == 0) {
                 if (nextReadBlock) {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index a14e88f9a0..b49a0d8ccb 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -111,6 +111,10 @@
         <bug>66276</bug>: Fix incorrect class cast when adding
         a descendant of HTTP/2 streams. (lihan)
       </fix>
+      <fix>
+        <bug>66281</bug>: Fix unexpected timeouts that may appear as client
+        disconnections when using HTTP/2 and NIO2. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org