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

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

commit 3c42ca9fe2263d507660a989ab65d5ba4f060cd5
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Mar 12 12:12:41 2021 +0000

    Simplify the closing of an HTTP/2 stream with an error condition
---
 java/org/apache/coyote/http2/StreamProcessor.java | 33 +++++++----------------
 webapps/docs/changelog.xml                        |  4 +++
 2 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/java/org/apache/coyote/http2/StreamProcessor.java 
b/java/org/apache/coyote/http2/StreamProcessor.java
index 7690380..95af082 100644
--- a/java/org/apache/coyote/http2/StreamProcessor.java
+++ b/java/org/apache/coyote/http2/StreamProcessor.java
@@ -74,7 +74,16 @@ class StreamProcessor extends AbstractProcessor {
                         
handler.getProtocol().getHttp11Protocol().addWaitingProcessor(this);
                     } else if (state == SocketState.CLOSED) {
                         
handler.getProtocol().getHttp11Protocol().removeWaitingProcessor(this);
-                        if (!getErrorState().isConnectionIoAllowed()) {
+                        if (!stream.isInputFinished() && 
getErrorState().isIoAllowed()) {
+                            // The request has been processed but the request 
body has not been
+                            // fully read. This typically occurs when Tomcat 
rejects an upload
+                            // of some form (e.g. PUT or POST). Need to tell 
the client not to
+                            // send any more data on this stream (reset).
+                            StreamException se = new StreamException(
+                                    sm.getString("streamProcessor.cancel", 
stream.getConnectionId(),
+                                            stream.getIdAsString()), 
Http2Error.CANCEL, stream.getIdAsInt());
+                            stream.close(se);
+                        } else if (!getErrorState().isConnectionIoAllowed()) {
                             ConnectionException ce = new 
ConnectionException(sm.getString(
                                     "streamProcessor.error.connection", 
stream.getConnectionId(),
                                     stream.getIdAsString()), 
Http2Error.INTERNAL_ERROR);
@@ -373,13 +382,6 @@ class StreamProcessor extends AbstractProcessor {
             setErrorState(ErrorState.CLOSE_NOW, e);
         }
 
-        if (!isAsync()) {
-            // If this is an async request then the request ends when it has
-            // been completed. The AsyncContext is responsible for calling
-            // endRequest() in that case.
-            endRequest();
-        }
-
         if (getErrorState().isError()) {
             action(ActionCode.CLOSE, null);
             request.updateCounters();
@@ -420,21 +422,6 @@ class StreamProcessor extends AbstractProcessor {
 
     @Override
     protected final SocketState dispatchEndRequest() throws IOException {
-        endRequest();
         return SocketState.CLOSED;
     }
-
-
-    private void endRequest() {
-        if (!stream.isInputFinished() && getErrorState().isIoAllowed()) {
-            // The request has been processed but the request body has not been
-            // fully read. This typically occurs when Tomcat rejects an upload
-            // of some form (e.g. PUT or POST). Need to tell the client not to
-            // send any more data on this stream (reset).
-            StreamException se = new StreamException(
-                    sm.getString("streamProcessor.cancel", 
stream.getConnectionId(),
-                            stream.getIdAsString()), Http2Error.CANCEL, 
stream.getIdAsInt());
-            stream.close(se);
-        }
-    }
 }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 69ccd4b..2be4fd4 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -119,6 +119,10 @@
         to recycle an HTTP/2 stream may result in
         <code>NullPointerException</code>s. (markt)
       </fix>
+      <scode>
+        Simplify the closing on an HTTP/2 stream when an error condition is
+        present. (markt)
+      </scode>
     </changelog>
   </subsection>
 </section>


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

Reply via email to