From a63584715fd605f4f867d82fc6e2488adfd00dcf Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Mon, 3 Jun 2019 08:43:19 +0200 Subject: [PATCH] ByteToMessageDecoder.handlerRemoved(...) should only call fireChannelReadComplete() if fireChannelRead(...) was called before (#9211) Motivation: At the moment ByteToMessageDecoder always calls fireChannelReadComplete() when the handler is removed from the pipeline and the cumulation buffer is not null. We should only call it when we also call fireChannelRead(...), which only happens if the cumulation buffer is not null and readable. Modifications: Only call fireChannelReadComplete() if fireChannelRead(...) is called before during removal of the handler. Result: More correct semantics --- .../java/io/netty/handler/codec/ByteToMessageDecoder.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java b/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java index 38f55858fc..67c09041b6 100644 --- a/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java @@ -235,18 +235,16 @@ public abstract class ByteToMessageDecoder extends ChannelHandlerAdapter impleme if (buf != null) { // Directly set this to null so we are sure we not access it in any other method here anymore. cumulation = null; - + numReads = 0; int readable = buf.readableBytes(); if (readable > 0) { ByteBuf bytes = buf.readBytes(readable); buf.release(); ctx.fireChannelRead(bytes); + ctx.fireChannelReadComplete(); } else { buf.release(); } - - numReads = 0; - ctx.fireChannelReadComplete(); } handlerRemoved0(ctx); }