Skip to content

Commit

Permalink
Make sure ChunkedInput.close() is not called before the write is comp…
Browse files Browse the repository at this point in the history
…lete. See #303
  • Loading branch information
normanmaurer committed May 3, 2012
1 parent abc2877 commit 7d2d742
Showing 1 changed file with 12 additions and 2 deletions.
Expand Up @@ -211,7 +211,7 @@ private synchronized void flush(ChannelHandlerContext ctx, boolean fireNow) thro
final MessageEvent currentEvent = this.currentEvent;
Object m = currentEvent.getMessage();
if (m instanceof ChunkedInput) {
ChunkedInput chunks = (ChunkedInput) m;
final ChunkedInput chunks = (ChunkedInput) m;
Object chunk;
boolean endOfInput;
boolean suspend;
Expand Down Expand Up @@ -248,8 +248,18 @@ private synchronized void flush(ChannelHandlerContext ctx, boolean fireNow) thro
ChannelFuture writeFuture;
if (endOfInput) {
this.currentEvent = null;
closeInput(chunks);
writeFuture = currentEvent.getFuture();

// Register a listener which will close the input once the write is complete. This is needed because the Chunk may have
// some resource bound that can not be closed before its not written
//
// See https://github.com/netty/netty/issues/303
writeFuture.addListener(new ChannelFutureListener() {

public void operationComplete(ChannelFuture future) throws Exception {
closeInput(chunks);
}
});
} else {
writeFuture = future(channel);
writeFuture.addListener(new ChannelFutureListener() {
Expand Down

0 comments on commit 7d2d742

Please sign in to comment.