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 aa48dd9  Fix potential deadlock with concurrent new frames and close 
for stream
aa48dd9 is described below

commit aa48dd90c654c778c224e4e4e827a4dce6a56305
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Jan 4 15:23:06 2022 +0000

    Fix potential deadlock with concurrent new frames and close for stream
---
 java/org/apache/coyote/http2/Stream.java | 11 +++++++++--
 webapps/docs/changelog.xml               |  4 ++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/coyote/http2/Stream.java 
b/java/org/apache/coyote/http2/Stream.java
index 8fee970..076226f 100644
--- a/java/org/apache/coyote/http2/Stream.java
+++ b/java/org/apache/coyote/http2/Stream.java
@@ -1251,17 +1251,24 @@ class Stream extends AbstractNonZeroStream implements 
HeaderEmitter {
                 closed = true;
             }
             if (inBuffer != null) {
+                int unreadByteCount = 0;
                 synchronized (inBuffer) {
-                    int unreadByteCount = inBuffer.position();
+                    unreadByteCount = inBuffer.position();
                     if (log.isDebugEnabled()) {
                         
log.debug(sm.getString("stream.inputBuffer.swallowUnread", 
Integer.valueOf(unreadByteCount)));
                     }
                     if (unreadByteCount > 0) {
                         inBuffer.position(0);
                         inBuffer.limit(inBuffer.limit() - unreadByteCount);
-                        handler.onSwallowedDataFramePayload(getIdAsInt(), 
unreadByteCount);
                     }
                 }
+                // Do this outside of the sync because:
+                // - it doesn't need to be inside the sync
+                // - if inside the sync it can trigger a deadlock
+                //   https://markmail.org/message/vbglzkvj6wxlhh3p
+                if (unreadByteCount > 0) {
+                    handler.onSwallowedDataFramePayload(getIdAsInt(), 
unreadByteCount);
+                }
             }
         }
     }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 7d95f41..fe1864e 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -323,6 +323,10 @@
         on MacOS as it does on Linux and Windows when no trusted certificate
         authorities are configured and reject all client certificates. (markt)
       </add>
+      <fix>
+        Avoid a potential deadlock during the concurrent processing of incoming
+        HTTP/2 frames for a stream and that stream being reset. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="WebSocket">

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to