Add patch of NETTY-434 to the mix to fix Deadlock in

ChunkedWriteHandler. This patch was not written by me...
This commit is contained in:
Norman Maurer 2011-09-30 22:14:36 +02:00 committed by Trustin Lee
parent 6ee3286784
commit 509edd86f4

View File

@ -154,34 +154,36 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns
private void discard(ChannelHandlerContext ctx) { private void discard(ChannelHandlerContext ctx) {
ClosedChannelException cause = null; ClosedChannelException cause = null;
boolean fireExceptionCaught = false; boolean fireExceptionCaught = false;
synchronized (this) {
for (;;) { for (;;) {
if (currentEvent == null) { MessageEvent currentEvent = this.currentEvent;
currentEvent = queue.poll();
} if (this.currentEvent == null) {
currentEvent = queue.poll();
if (currentEvent == null) { } else {
break; this.currentEvent = null;
}
MessageEvent currentEvent = this.currentEvent;
this.currentEvent = null;
Object m = currentEvent.getMessage();
if (m instanceof ChunkedInput) {
closeInput((ChunkedInput) m);
}
// Trigger a ClosedChannelException
if (cause == null) {
cause = new ClosedChannelException();
}
currentEvent.getFuture().setFailure(cause);
fireExceptionCaught = true;
currentEvent = null;
} }
if (currentEvent == null) {
break;
}
Object m = currentEvent.getMessage();
if (m instanceof ChunkedInput) {
closeInput((ChunkedInput) m);
}
// Trigger a ClosedChannelException
if (cause == null) {
cause = new ClosedChannelException();
}
currentEvent.getFuture().setFailure(cause);
fireExceptionCaught = true;
currentEvent = null;
} }
if (fireExceptionCaught) { if (fireExceptionCaught) {
Channels.fireExceptionCaught(ctx.getChannel(), cause); Channels.fireExceptionCaught(ctx.getChannel(), cause);