diff --git a/common/src/main/java/org/wildfly/httpclient/common/WildflyClientOutputStream.java b/common/src/main/java/org/wildfly/httpclient/common/WildflyClientOutputStream.java index 2dd3376e..1899225f 100644 --- a/common/src/main/java/org/wildfly/httpclient/common/WildflyClientOutputStream.java +++ b/common/src/main/java/org/wildfly/httpclient/common/WildflyClientOutputStream.java @@ -94,16 +94,17 @@ public void handleEvent(StreamSinkChannel streamSinkChannel) { return; } } - lock.notifyAll(); - streamSinkChannel.suspendWrites(); - state &= ~FLAG_WRITING; pooledBuffer.close(); pooledBuffer = null; + if (closed && !streamSinkChannel.flush()) { + return; + } if (closed) { - if (streamSinkChannel.flush()) { - state |= FLAG_DONE; - } + state |= FLAG_DONE; } + streamSinkChannel.suspendWrites(); + state &= ~FLAG_WRITING; + lock.notifyAll(); } } catch (IOException e) { if (pooledBuffer != null) {