From b89487c4456134459427a75d1840749bae7d65c2 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Fri, 30 Sep 2011 22:14:36 +0200 Subject: [PATCH] Add patch of NETTY-434 to the mix to fix Deadlock in ChunkedWriteHandler. This patch was not written by me... --- .../handler/stream/ChunkedWriteHandler.java | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/jboss/netty/handler/stream/ChunkedWriteHandler.java b/src/main/java/org/jboss/netty/handler/stream/ChunkedWriteHandler.java index ea6d8a6d98..92c9bf08c0 100644 --- a/src/main/java/org/jboss/netty/handler/stream/ChunkedWriteHandler.java +++ b/src/main/java/org/jboss/netty/handler/stream/ChunkedWriteHandler.java @@ -152,34 +152,36 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns private void discard(ChannelHandlerContext ctx) { ClosedChannelException cause = null; boolean fireExceptionCaught = false; - synchronized (this) { - for (;;) { - if (currentEvent == null) { - currentEvent = queue.poll(); - } - - if (currentEvent == null) { - break; - } - - 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; + + for (;;) { + MessageEvent currentEvent = this.currentEvent; + + if (this.currentEvent == null) { + currentEvent = queue.poll(); + } else { + this.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) { Channels.fireExceptionCaught(ctx.getChannel(), cause);