From d6f0d12a8692c095df43b2a4462cbc97cf5c5a2d Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Thu, 31 Jul 2014 15:25:09 -0700 Subject: [PATCH] Fix a bug in ChannelOutboundBuffer.nioBuffers() Related issue: #2717, #2710, #2704, #2693 Motivation: When ChannelOutboundBuffer.nioBuffers() iterates over the linked list of entries, it is not supposed to visit unflushed entries, but it does. Modifications: - Make sure ChannelOutboundBuffer.nioBuffers() stops the iteration before it visits an unflushed entry - Add isFlushedEntry() to reduce the chance of the similar mistakes Result: Another regression is gone. --- .../main/java/io/netty/channel/ChannelOutboundBuffer.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java b/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java index 062b944563..4f9ea669c3 100644 --- a/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java +++ b/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java @@ -356,7 +356,7 @@ public final class ChannelOutboundBuffer { final InternalThreadLocalMap threadLocalMap = InternalThreadLocalMap.get(); ByteBuffer[] nioBuffers = NIO_BUFFERS.get(threadLocalMap); Entry entry = flushedEntry; - while (entry != null && entry.msg instanceof ByteBuf) { + while (isFlushedEntry(entry) && entry.msg instanceof ByteBuf) { if (!entry.cancelled) { ByteBuf buf = (ByteBuf) entry.msg; final int readerIndex = buf.readerIndex(); @@ -586,7 +586,11 @@ public final class ChannelOutboundBuffer { } } entry = entry.next; - } while (entry != null && entry != unflushedEntry); + } while (isFlushedEntry(entry)); + } + + private boolean isFlushedEntry(Entry e) { + return e != null && e != unflushedEntry; } public interface MessageProcessor {