This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push:
new 42e2ef2 Follow-up to e967bbc. Provide a sync but on a different
object.
42e2ef2 is described below
commit 42e2ef20c75b63941b2f0bade520963da711b836
Author: Mark Thomas <[email protected]>
AuthorDate: Fri Jun 7 11:55:29 2019 +0100
Follow-up to e967bbc. Provide a sync but on a different object.
As identified by BZ 61740, headers must be written in the same order
they are generated because the compression algorithm used maintains
state across multiple request/response pairs.
Sync on a dedicated object to ensure that this is the case.
---
.../coyote/http2/Http2AsyncUpgradeHandler.java | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/java/org/apache/coyote/http2/Http2AsyncUpgradeHandler.java
b/java/org/apache/coyote/http2/Http2AsyncUpgradeHandler.java
index 8a57c53..3115eda 100644
--- a/java/org/apache/coyote/http2/Http2AsyncUpgradeHandler.java
+++ b/java/org/apache/coyote/http2/Http2AsyncUpgradeHandler.java
@@ -39,6 +39,10 @@ import
org.apache.tomcat.util.net.SocketWrapperBase.BlockingMode;
public class Http2AsyncUpgradeHandler extends Http2UpgradeHandler {
private static final ByteBuffer[] BYTEBUFFER_ARRAY = new ByteBuffer[0];
+ // 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 Throwable error = null;
private IOException applicationIOE = null;
@@ -169,13 +173,15 @@ public class Http2AsyncUpgradeHandler extends
Http2UpgradeHandler {
@Override
void writeHeaders(Stream stream, int pushedStreamId, MimeHeaders
mimeHeaders,
boolean endOfStream, int payloadSize) throws IOException {
- AsyncHeaderFrameBuffers headerFrameBuffers = (AsyncHeaderFrameBuffers)
- doWriteHeaders(stream, pushedStreamId, mimeHeaders,
endOfStream, payloadSize);
- if (headerFrameBuffers != null) {
- socketWrapper.write(BlockingMode.SEMI_BLOCK,
protocol.getWriteTimeout(),
- TimeUnit.MILLISECONDS, null,
SocketWrapperBase.COMPLETE_WRITE,
- applicationErrorCompletion,
headerFrameBuffers.bufs.toArray(BYTEBUFFER_ARRAY));
- handleAsyncException();
+ synchronized (headerWriteLock) {
+ AsyncHeaderFrameBuffers headerFrameBuffers =
(AsyncHeaderFrameBuffers)
+ doWriteHeaders(stream, pushedStreamId, mimeHeaders,
endOfStream, payloadSize);
+ if (headerFrameBuffers != null) {
+ socketWrapper.write(BlockingMode.SEMI_BLOCK,
protocol.getWriteTimeout(),
+ TimeUnit.MILLISECONDS, null,
SocketWrapperBase.COMPLETE_WRITE,
+ applicationErrorCompletion,
headerFrameBuffers.bufs.toArray(BYTEBUFFER_ARRAY));
+ handleAsyncException();
+ }
}
if (endOfStream) {
stream.sentEndOfStream();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]