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 50f627546f Refactor to reduce pinning in HTTP/2 code when using
virtual threads
50f627546f is described below
commit 50f627546f085ae64aff4c3e4465d4cd797a685c
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Jul 26 13:23:39 2023 +0100
Refactor to reduce pinning in HTTP/2 code when using virtual threads
---
.../apache/coyote/http2/Http2AsyncUpgradeHandler.java | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/java/org/apache/coyote/http2/Http2AsyncUpgradeHandler.java
b/java/org/apache/coyote/http2/Http2AsyncUpgradeHandler.java
index 1b86d0da05..d9f69464f6 100644
--- a/java/org/apache/coyote/http2/Http2AsyncUpgradeHandler.java
+++ b/java/org/apache/coyote/http2/Http2AsyncUpgradeHandler.java
@@ -26,6 +26,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import javax.servlet.http.WebConnection;
@@ -44,9 +46,9 @@ public class Http2AsyncUpgradeHandler extends
Http2UpgradeHandler {
// Ensures headers are generated and then written for one thread at a time.
// Because of the compression used, headers need to be written to the
// network in the same order they are generated.
- private final Object headerWriteLock = new Object();
+ private final Lock headerWriteLock = new ReentrantLock();
// Ensures thread triggers the stream reset is the first to send a RST
frame
- private final Object sendResetLock = new Object();
+ private final Lock sendResetLock = new ReentrantLock();
private final AtomicReference<Throwable> error = new AtomicReference<>();
private final AtomicReference<IOException> applicationIOE = new
AtomicReference<>();
@@ -148,7 +150,8 @@ public class Http2AsyncUpgradeHandler extends
Http2UpgradeHandler {
// may see out of order RST frames which may hard to follow if
// the client is unaware the RST frames may be received out of
// order.
- synchronized (sendResetLock) {
+ sendResetLock.lock();
+ try {
if (state != null) {
boolean active = state.isActive();
state.sendReset();
@@ -159,6 +162,8 @@ public class Http2AsyncUpgradeHandler extends
Http2UpgradeHandler {
socketWrapper.write(BlockingMode.SEMI_BLOCK,
protocol.getWriteTimeout(), TimeUnit.MILLISECONDS, null,
SocketWrapperBase.COMPLETE_WRITE, errorCompletion,
ByteBuffer.wrap(rstFrame));
+ } finally {
+ sendResetLock.unlock();
}
handleAsyncException();
}
@@ -191,7 +196,8 @@ public class Http2AsyncUpgradeHandler extends
Http2UpgradeHandler {
@Override
void writeHeaders(Stream stream, int pushedStreamId, MimeHeaders
mimeHeaders, boolean endOfStream, int payloadSize)
throws IOException {
- synchronized (headerWriteLock) {
+ headerWriteLock.lock();
+ try {
AsyncHeaderFrameBuffers headerFrameBuffers =
(AsyncHeaderFrameBuffers) doWriteHeaders(stream,
pushedStreamId, mimeHeaders, endOfStream, payloadSize);
if (headerFrameBuffers != null) {
@@ -200,6 +206,8 @@ public class Http2AsyncUpgradeHandler extends
Http2UpgradeHandler {
headerFrameBuffers.bufs.toArray(BYTEBUFFER_ARRAY));
handleAsyncException();
}
+ } finally {
+ headerWriteLock.unlock();
}
if (endOfStream) {
sentEndOfStream(stream);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]