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


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 56ba62e2fc Refactor to reduce pinning in HTTP/2 code when using 
virtual threads
56ba62e2fc is described below

commit 56ba62e2fc60c550a8b90a54452f78683a682ea0
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jul 26 10:34:38 2023 +0100

    Refactor to reduce pinning in HTTP/2 code when using virtual threads
---
 java/org/apache/coyote/http2/StreamProcessor.java | 10 ++++++++--
 webapps/docs/changelog.xml                        |  4 ++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/coyote/http2/StreamProcessor.java 
b/java/org/apache/coyote/http2/StreamProcessor.java
index 4b06ff9b71..8d8af36852 100644
--- a/java/org/apache/coyote/http2/StreamProcessor.java
+++ b/java/org/apache/coyote/http2/StreamProcessor.java
@@ -22,6 +22,8 @@ import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
 
 import javax.servlet.http.HttpServletResponse;
 
@@ -55,6 +57,7 @@ class StreamProcessor extends AbstractProcessor {
 
     private static final Set<String> H2_PSEUDO_HEADERS_REQUEST = new 
HashSet<>();
 
+    private final Lock processLock = new ReentrantLock();
     private final Http2UpgradeHandler handler;
     private final Stream stream;
     private SendfileData sendfileData = null;
@@ -77,8 +80,9 @@ class StreamProcessor extends AbstractProcessor {
 
     final void process(SocketEvent event) {
         try {
-            // FIXME: the regular processor syncs on socketWrapper, but here 
this deadlocks
-            synchronized (this) {
+            // Note: The regular processor uses the socketWrapper lock, but 
using that here triggers a deadlock
+            processLock.lock();
+            try {
                 // HTTP/2 equivalent of AbstractConnectionHandler#process() 
without the
                 // socket <-> processor mapping
                 SocketState state = SocketState.CLOSED;
@@ -134,6 +138,8 @@ class StreamProcessor extends AbstractProcessor {
                         recycle();
                     }
                 }
+            } finally {
+                processLock.unlock();
             }
         } finally {
             handler.executeQueuedStream();
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 3d7f7256a8..f8b8f3f95e 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -143,6 +143,10 @@
         <code>certificateKeystoreFile</code> attribute of an
         <code>SSLHostConfigCertificate</code> instance. (markt)
       </fix>
+      <scode>
+        Refactor HTTP/2 implementation to reduce pinning when using virtual
+        threads. (markt)
+      </scode>
     </changelog>
   </subsection>
   <subsection name="WebSocket">


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

Reply via email to