diff options
author | Bjørn Christian Seime <bjorncs@yahoo-inc.com> | 2016-11-30 20:34:25 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@yahoo-inc.com> | 2016-11-30 20:49:39 +0100 |
commit | 1a7c996b6214725d0c3589b4cf2f0eb20a18d3cd (patch) | |
tree | 15ef9f232c6810abba78fa448e8424c7816fff7a /jdisc_http_service/src | |
parent | 22367afcf95be8e80db1ca429d55598c64517c98 (diff) |
Use more fine grained locking
Diffstat (limited to 'jdisc_http_service/src')
-rw-r--r-- | jdisc_http_service/src/main/java/com/yahoo/jdisc/http/server/jetty/ServletOutputStreamWriter.java | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/server/jetty/ServletOutputStreamWriter.java b/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/server/jetty/ServletOutputStreamWriter.java index 5c831a3dd65..eb782737a0c 100644 --- a/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/server/jetty/ServletOutputStreamWriter.java +++ b/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/server/jetty/ServletOutputStreamWriter.java @@ -81,18 +81,33 @@ public class ServletOutputStreamWriter { } public void sendErrorContentAndCloseAsync(ByteBuffer errorContent) { + boolean thisThreadShouldWrite; + synchronized (monitor) { // Assert that no content has been written as it is too late to write error response if the response is committed. switch (state) { case NOT_STARTED: + queueErrorContent_holdingLock(errorContent); + state = State.WAITING_FOR_WRITE_POSSIBLE_CALLBACK; + thisThreadShouldWrite = false; + break; case WAITING_FOR_FIRST_BUFFER: - writeBuffer(errorContent, null); - close(null); - return; + queueErrorContent_holdingLock(errorContent); + state = State.WRITING_BUFFERS; + thisThreadShouldWrite = true; + break; default: throw createAndLogAssertionError("Invalid state: " + state); } } + if (thisThreadShouldWrite) { + writeBuffersInQueueToOutputStream(); + } + } + + private void queueErrorContent_holdingLock(ByteBuffer errorContent) { + responseContentQueue.addLast(new ResponseContentPart(errorContent, null)); + responseContentQueue.addLast(new ResponseContentPart(CLOSE_STREAM_BUFFER, null)); } public void writeBuffer(ByteBuffer buf, CompletionHandler handler) { |