Make sure ChunkedInput.close() is not called before the write is complete. See #303

This commit is contained in:
norman 2012-05-03 09:17:37 +02:00
parent abc2877f91
commit 7d2d742a43

View File

@ -211,7 +211,7 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns
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;
@ -248,8 +248,18 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns
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() {