Skip to content

Commit

Permalink
Refactor to reduce pinning in HTTP/2 code when using virtual threads
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Jul 26, 2023
1 parent 65ba2e1 commit 6090a5e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 8 additions & 2 deletions java/org/apache/coyote/http2/StreamProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -134,6 +138,8 @@ final void process(SocketEvent event) {
recycle();
}
}
} finally {
processLock.unlock();
}
} finally {
handler.executeQueuedStream();
Expand Down
4 changes: 4 additions & 0 deletions webapps/docs/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,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">
Expand Down

0 comments on commit 6090a5e

Please sign in to comment.