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
This commit is contained in:
Norman Maurer 2019-06-03 08:43:19 +02:00 committed by GitHub
parent ec69da9afb
commit b91889c3db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -241,18 +241,16 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter
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);
}