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

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

commit b16ffe56dd3238bdd91139f4a05116375b2b3d05
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 | 41 ++++++-----------------
 webapps/docs/changelog.xml                        |  4 +++
 2 files changed, 14 insertions(+), 31 deletions(-)

diff --git a/java/org/apache/coyote/http2/StreamProcessor.java 
b/java/org/apache/coyote/http2/StreamProcessor.java
index 2e757eb..d1ae2f9 100644
--- a/java/org/apache/coyote/http2/StreamProcessor.java
+++ b/java/org/apache/coyote/http2/StreamProcessor.java
@@ -77,7 +77,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);
@@ -410,13 +419,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 (sendfileState == SendfileState.PENDING) {
             return SocketState.SENDFILE;
         } else if (getErrorState().isError()) {
@@ -459,29 +461,6 @@ class StreamProcessor extends AbstractProcessor {
 
     @Override
     protected final SocketState dispatchEndRequest() throws IOException {
-        endRequest();
         return SocketState.CLOSED;
     }
-
-
-    private void endRequest() {
-        if (!stream.isInputFinished() && getErrorState().isIoAllowed()) {
-            if (handler.hasAsyncIO() && !stream.isContentLengthInconsistent()) 
{
-                // Need an additional checks for asyncIO as the end of stream
-                // might have been set on the header frame but not processed
-                // yet. Checking for this here so the extra processing only
-                // occurs on the potential error condition rather than on every
-                // request.
-                return;
-            }
-            // 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 e31899e..8135161 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -115,6 +115,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