Skip to content

Commit

Permalink
Avoid infinite waiting for consumer close (#11347)
Browse files Browse the repository at this point in the history
### Motivation
If there are two Events
- EventA: Server close the consumer
- EventB: consumer close self

If EventA and EventB concurrently, then the `cnx.ctx()` has probability to be null. Which occurs a NPE, lead to infinite wait future

### Modifications

If the `cnx.ctx()` is already null, we ignore the exception too.
  • Loading branch information
shoothzj committed Jul 22, 2021
1 parent b72635d commit 4d3fdae
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.Recycler;
import io.netty.util.Recycler.Handle;
import io.netty.util.ReferenceCountUtil;
Expand Down Expand Up @@ -926,7 +927,8 @@ public CompletableFuture<Void> closeAsync() {
} else {
ByteBuf cmd = Commands.newCloseConsumer(consumerId, requestId);
cnx.sendRequestWithId(cmd, requestId).handle((v, exception) -> {
boolean ignoreException = !cnx.ctx().channel().isActive();
final ChannelHandlerContext ctx = cnx.ctx();
boolean ignoreException = ctx == null || !ctx.channel().isActive();
if (ignoreException && exception != null) {
log.debug("Exception ignored in closing consumer", exception);
}
Expand Down

0 comments on commit 4d3fdae

Please sign in to comment.