This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new 8044fc73b4 Refactor to reduce pinning in HTTP/2 code when using
virtual threads
8044fc73b4 is described below
commit 8044fc73b4e987d8e75a199dcdc907155dd0f6eb
Author: Mark Thomas <[email protected]>
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 e22afa030d..4b7990faea 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 jakarta.servlet.ServletConnection;
import jakarta.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 460ea09733..246b17c9c3 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -122,6 +122,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: [email protected]
For additional commands, e-mail: [email protected]