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 905e6bbd47 Refactor to reduce pinning in HTTP/2 code when using
virtual threads
905e6bbd47 is described below
commit 905e6bbd47cc6d80d787ee833c5697f0a9f7f532
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 9372037f3d..0a0868d477 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 jakarta.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<>();
@@ -149,7 +151,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();
@@ -160,6 +163,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();
}
@@ -192,7 +197,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) {
@@ -201,6 +207,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]