From 39f6f87ca7c5b01dc438a9a3c8425650c199b9dc Mon Sep 17 00:00:00 2001 From: gregw Date: Thu, 4 Feb 2021 10:26:11 +0100 Subject: [PATCH] Fix #5605 Unblock non container Threads Simplification. Always abort on any pending read or write in completion. --- .../java/org/eclipse/jetty/server/HttpOutput.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java index 2afa950d18c0..2b424ed40fb2 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java @@ -455,12 +455,19 @@ public void complete(Callback callback) LOG.warn("Pending write onComplated {} {}", this, _channel); // An operation is in progress, so we soft close now _softClose = true; - // then cancel the operation and abort the channel - CancellationException cancelled = new CancellationException(); - _writeBlocker.fail(cancelled); - _channel.abort(cancelled); // then trigger a close from onWriteComplete _state = State.CLOSE; + + // But if we are blocked or there is more content to come, we must abort + // Note that this allows a pending async write to complete only if it is the last write + if (_apiState == ApiState.BLOCKED || !_channel.getResponse().isContentComplete(_written)) + { + CancellationException cancelled = new CancellationException(); + _writeBlocker.fail(cancelled); + _channel.abort(cancelled); + _state = State.CLOSED; + } + break; } break;