diff --git a/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java b/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java index 4651adc457..b99343f399 100644 --- a/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java +++ b/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java @@ -113,6 +113,7 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel { try { do { byteBuf = allocHandle.allocate(allocator); + int writable = byteBuf.writableBytes(); int localReadAmount = doReadBytes(byteBuf); if (localReadAmount <= 0) { // not was read release the buffer @@ -123,6 +124,10 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel { pipeline.fireChannelRead(byteBuf); byteBuf = null; allocHandle.record(localReadAmount); + if (localReadAmount < writable) { + // we read less then what the buffer can hold so it seems like we drained it completely + break; + } } while (++ messages < maxMessagesPerRead); pipeline.fireChannelReadComplete();