Skip to content

Commit

Permalink
ByteToMessageDecoder.handlerRemoved(...) should only call fireChannel…
Browse files Browse the repository at this point in the history
…ReadComplete() 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
  • Loading branch information
normanmaurer committed Jun 3, 2019
1 parent b5ff56b commit a635847
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,16 @@ public final void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
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);
}
Expand Down

0 comments on commit a635847

Please sign in to comment.