diff options
Diffstat (limited to 'jdisc_http_service')
-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) { |