Yes this sounds good.... can you provide a PR?

> Am 30.03.2018 um 14:24 schrieb Nicolae Mihalache <notifications@github.com>:
> 
> Hello,
> 
> I get an exception "promise already done" apparently caused by the ChunkedWriteHandler which is called twice for the same message, one from my flush and the other time from the channelWritabilityChanged.
> 
> Not sure if the ChunkedWriteHandler.doFlush method is supposed to be called twice in the same write but it looks to work ok when it's called twice and the message is ChunkedInput.
> 
> Maybe lines 304 and 305 should be reversed from:
> 
>                 ctx.write(pendingMessage, currentWrite.promise);
>                 this.currentWrite = null;
> to:
> 
>                 this.currentWrite = null;
>                 ctx.write(pendingMessage, currentWrite.promise);
> A stacktrace is attached.
> stack-trace.txt
> 
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub, or mute the thread.
> 

promise already done caused by ChunkedWriteHandler writing the same (non chunked) message twice
Hello,

I get an exception "promise already done" apparently caused by the ChunkedWriteHandler which is called twice for the same message, one from my flush and the other time from the channelWritabilityChanged.

Not sure if the ChunkedWriteHandler.doFlush method is supposed to be called twice in the same write but it looks to work ok when it's called twice and the message is ChunkedInput.

Maybe lines 304 and 305 should be reversed from:
```
                ctx.write(pendingMessage, currentWrite.promise);
                this.currentWrite = null;
```
to:
```
                this.currentWrite = null;
                ctx.write(pendingMessage, currentWrite.promise);
```

A stacktrace is attached.
[stack-trace.txt](https://github.com/netty/netty/files/1863541/stack-trace.txt)


handler/src/main/java/io/netty/handler/stream/ChunkedWriteHandler.java
handler/src/main/java/io/netty/handler/stream/ChunkedWriteHandler.java
diff --git a/handler/src/main/java/io/netty/handler/stream/ChunkedWriteHandler.java b/handler/src/main/java/io/netty/handler/stream/ChunkedWriteHandler.java
index 1bc0c6bf81d..6f753c5c510 100644
--- a/handler/src/main/java/io/netty/handler/stream/ChunkedWriteHandler.java
+++ b/handler/src/main/java/io/netty/handler/stream/ChunkedWriteHandler.java
@@ -299,8 +299,8 @@ public void operationComplete(ChannelFuture future) throws Exception {
                 ctx.flush();
                 requiresFlush = false;
             } else {
-                ctx.write(pendingMessage, currentWrite.promise);
                 this.currentWrite = null;
+                ctx.write(pendingMessage, currentWrite.promise);
                 requiresFlush = true;
             }
 
