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 7977615c10 Fix duplicate Poller registration with HTTP/2, NIO and async IO 7977615c10 is described below commit 7977615c10b669c50bbca7fbdd890478029aa517 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 8134955c2f..449d662f54 100644 --- a/java/org/apache/coyote/AbstractProtocol.java +++ b/java/org/apache/coyote/AbstractProtocol.java @@ -910,7 +910,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; } } } @@ -946,6 +946,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 426d0bfa9c..d0a9b21724 100644 --- a/java/org/apache/coyote/http2/Http2UpgradeHandler.java +++ b/java/org/apache/coyote/http2/Http2UpgradeHandler.java @@ -393,14 +393,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 da280ce4a8..05fe1fa834 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 f33e004e4c..fa87fc1c1c 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -145,6 +145,10 @@ Correct a regression in the refactoring to support experimentation with project Loom that broke HTTP/2 support if async IO was disabled. (markt) </fix> + <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