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

commit 2426f4881a7de32e50ceaf8ec97f8c232ae6e597
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Tue Jun 28 20:31:41 2022 +0100

    Fix duplicate Poller registration with HTTP/2, NIO and async IO
    
    This could cause HTTP/2 connections to unexpectedly fail
---
 java/org/apache/coyote/AbstractProtocol.java          |  5 ++++-
 java/org/apache/coyote/http2/Http2UpgradeHandler.java | 13 ++++++++++---
 java/org/apache/tomcat/util/net/AbstractEndpoint.java |  2 +-
 webapps/docs/changelog.xml                            |  4 ++++
 4 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/java/org/apache/coyote/AbstractProtocol.java 
b/java/org/apache/coyote/AbstractProtocol.java
index a3331c175a..09367766d6 100644
--- a/java/org/apache/coyote/AbstractProtocol.java
+++ b/java/org/apache/coyote/AbstractProtocol.java
@@ -919,7 +919,7 @@ public abstract class AbstractProtocol<S> implements 
ProtocolHandler,
                             if (httpUpgradeHandler instanceof 
InternalHttpUpgradeHandler) {
                                 if (((InternalHttpUpgradeHandler) 
httpUpgradeHandler).hasAsyncIO()) {
                                     // The handler will initiate all further 
I/O
-                                    state = SocketState.UPGRADED;
+                                    state = SocketState.ASYNC_IO;
                                 }
                             }
                         }
@@ -955,6 +955,9 @@ public abstract class AbstractProtocol<S> implements 
ProtocolHandler,
                         longPoll(wrapper, processor);
                         getProtocol().addWaitingProcessor(processor);
                     }
+                } else if (state == SocketState.ASYNC_IO) {
+                    // Don't add sockets back to the poller.
+                    // The handler will initiate all further I/O
                 } else if (state == SocketState.SUSPENDED) {
                     // Don't add sockets back to the poller.
                     // The resumeProcessing() method will add this socket
diff --git a/java/org/apache/coyote/http2/Http2UpgradeHandler.java 
b/java/org/apache/coyote/http2/Http2UpgradeHandler.java
index 8b7ec85cc5..fed4383972 100644
--- a/java/org/apache/coyote/http2/Http2UpgradeHandler.java
+++ b/java/org/apache/coyote/http2/Http2UpgradeHandler.java
@@ -388,14 +388,21 @@ class Http2UpgradeHandler extends AbstractStream 
implements InternalHttpUpgradeH
                 }
 
                 if (connectionState.get() != ConnectionState.CLOSED) {
-                    result = SocketState.UPGRADED;
+                    if (socketWrapper.hasAsyncIO()) {
+                        result = SocketState.ASYNC_IO;
+                    } else {
+                        result = SocketState.UPGRADED;
+                    }
                 }
                 break;
 
             case OPEN_WRITE:
                 processWrites();
-
-                result = SocketState.UPGRADED;
+                if (socketWrapper.hasAsyncIO()) {
+                    result = SocketState.ASYNC_IO;
+                } else {
+                    result = SocketState.UPGRADED;
+                }
                 break;
 
             case TIMEOUT:
diff --git a/java/org/apache/tomcat/util/net/AbstractEndpoint.java 
b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
index 572901a9fb..d058703953 100644
--- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
@@ -77,7 +77,7 @@ public abstract class AbstractEndpoint<S,U> {
         public enum SocketState {
             // TODO Add a new state to the AsyncStateMachine and remove
             //      ASYNC_END (if possible)
-            OPEN, CLOSED, LONG, ASYNC_END, SENDFILE, UPGRADING, UPGRADED, 
SUSPENDED
+            OPEN, CLOSED, LONG, ASYNC_END, SENDFILE, UPGRADING, UPGRADED, 
ASYNC_IO, SUSPENDED
         }
 
 
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 03eca51763..3943cd54ff 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -132,6 +132,10 @@
         default value for the <code>jmvRoute</code> attribute of an Engine.
         (markt)
       </scode>
+      <fix>
+        Fix duplicate Poller registration with HTTP/2, NIO and async IO that
+        could cause HTTP/2 connections to unexpectedly fail. (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