From 3412003bc25c253fbad0085cdbcf55e595f6d94e Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Thu, 18 Feb 2010 04:29:58 +0000 Subject: [PATCH] Fixed an infinite loop --- .../netty/handler/stream/ChunkedWriteHandler.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 b43abf04da..c9c69d3dee 100644 --- a/src/main/java/org/jboss/netty/handler/stream/ChunkedWriteHandler.java +++ b/src/main/java/org/jboss/netty/handler/stream/ChunkedWriteHandler.java @@ -172,10 +172,14 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns ChunkedInput chunks = (ChunkedInput) m; Object chunk; boolean endOfInput; + boolean later; try { chunk = chunks.nextChunk(); if (chunk == null) { chunk = ChannelBuffers.EMPTY_BUFFER; + later = true; + } else { + later = false; } endOfInput = chunks.isEndOfInput(); } catch (Throwable t) { @@ -211,6 +215,12 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns Channels.write( ctx, writeFuture, chunk, currentEvent.getRemoteAddress()); + + if (later) { + // ChunkedInput.nextChunk() returned null. + // Let's wait until more chunks arrive. + break; + } } else { ctx.sendDownstream(currentEvent); currentEvent = null;