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;