diff --git a/handler/src/main/java/io/netty/handler/flow/FlowControlHandler.java b/handler/src/main/java/io/netty/handler/flow/FlowControlHandler.java index 46f2993f9d..d8888570eb 100644 --- a/handler/src/main/java/io/netty/handler/flow/FlowControlHandler.java +++ b/handler/src/main/java/io/netty/handler/flow/FlowControlHandler.java @@ -87,7 +87,7 @@ public class FlowControlHandler implements ChannelHandler { * testing, debugging and inspection purposes and it is not Thread safe! */ boolean isQueueEmpty() { - return queue.isEmpty(); + return queue == null || queue.isEmpty(); } /** @@ -189,8 +189,13 @@ public class FlowControlHandler implements ChannelHandler { // We're firing a completion event every time one (or more) // messages were consumed and the queue ended up being drained // to an empty state. - if (queue.isEmpty() && consumed > 0) { - ctx.fireChannelReadComplete(); + if (queue.isEmpty()) { + queue.recycle(); + queue = null; + + if (consumed > 0) { + ctx.fireChannelReadComplete(); + } } return consumed;