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 52e0fd5f..17ea3692 100644 --- a/common/src/main/java/org/wildfly/httpclient/common/WildflyClientOutputStream.java +++ b/common/src/main/java/org/wildfly/httpclient/common/WildflyClientOutputStream.java @@ -66,6 +66,9 @@ public void handleEvent(StreamSinkChannel streamSinkChannel) { } try { boolean closed = anyAreSet(state, FLAG_CLOSED); + if (pooledBuffer != null) { + pooledBuffer.getBuffer().flip(); + } if (closed && (pooledBuffer == null || !pooledBuffer.getBuffer().hasRemaining())) { if (pooledBuffer != null) { pooledBuffer.close(); @@ -76,6 +79,7 @@ public void handleEvent(StreamSinkChannel streamSinkChannel) { state |= FLAG_DONE; state &= ~FLAG_WRITING; lock.notifyAll(); + streamSinkChannel.shutdownWrites(); } } else { while (pooledBuffer.getBuffer().hasRemaining()) { @@ -182,9 +186,6 @@ public void write(final byte[] b, final int off, final int len) throws IOExcepti private void runWriteTask() { Assert.assertHoldsLock(lock); - if (pooledBuffer != null) { - pooledBuffer.getBuffer().flip(); - } state |= FLAG_WRITING; channel.getWriteSetter().set(channelListener); channel.wakeupWrites();