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

commit c688f8d0b728ca37ffad44d7f50f1aa5778c200f
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Sep 24 15:50:35 2020 +0100

    Improve handling of HTTP/2 connection preface
    
    Only process the connection if the preface is processed without error.
    If an error is detected, trigger the connection close.
---
 java/org/apache/coyote/http2/Http2AsyncParser.java | 9 +++++----
 webapps/docs/changelog.xml                         | 5 +++++
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/java/org/apache/coyote/http2/Http2AsyncParser.java 
b/java/org/apache/coyote/http2/Http2AsyncParser.java
index 2452572..12fa3bb 100644
--- a/java/org/apache/coyote/http2/Http2AsyncParser.java
+++ b/java/org/apache/coyote/http2/Http2AsyncParser.java
@@ -35,7 +35,7 @@ class Http2AsyncParser extends Http2Parser {
 
     private final SocketWrapperBase<?> socketWrapper;
     private final Http2AsyncUpgradeHandler upgradeHandler;
-    private Throwable error = null;
+    private volatile Throwable error = null;
 
     Http2AsyncParser(String connectionId, Input input, Output output, 
SocketWrapperBase<?> socketWrapper, Http2AsyncUpgradeHandler upgradeHandler) {
         super(connectionId, input, output);
@@ -117,13 +117,14 @@ class Http2AsyncParser extends Http2Parser {
                 if (payload.hasRemaining()) {
                     socketWrapper.unRead(payload);
                 }
+                // Finish processing the connection
+                upgradeHandler.processConnectionCallback(webConnection, 
stream);
+            } else {
+                upgradeHandler.closeConnection(new 
ConnectionException(error.getMessage(), Http2Error.PROTOCOL_ERROR, error));
             }
-            // Finish processing the connection
-            upgradeHandler.processConnectionCallback(webConnection, stream);
             // Continue reading frames
             upgradeHandler.upgradeDispatch(SocketEvent.OPEN_READ);
         }
-
     }
 
     @Override
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 32c2ba7..06ec832 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -114,6 +114,11 @@
         in-flight asynchronous requests. The tracking enables Tomcat to 
shutdown
         gracefully when asynchronous processing is in use. (markt)
       </fix>
+      <fix>
+        Improve the error handling for the HTTP/2 connection preface when the
+        Connector is configured with <code>useAsycIO=&quot;true&quot;</code>.
+        (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