You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/04/29 08:05:28 UTC

[GitHub] [pulsar] lhotari commented on a diff in pull request #15382: [Broker/Client] Close connection if a ping message cannot be sent

lhotari commented on code in PR #15382:
URL: https://github.com/apache/pulsar/pull/15382#discussion_r861556999


##########
pulsar-common/src/main/java/org/apache/pulsar/common/protocol/PulsarHandler.java:
##########
@@ -110,7 +110,14 @@ private void handleKeepAliveTimeout() {
                 log.debug("[{}] Sending ping message", ctx.channel());
             }
             waitingForPingResponse = true;
-            ctx.writeAndFlush(Commands.newPing());
+            ctx.writeAndFlush(Commands.newPing())
+                    .addListener(future -> {
+                        if (!future.isSuccess()) {
+                            log.warn("[{}] Forcing connection to close since cannot send a ping message.",
+                                    ctx.channel(), future.cause());
+                            ctx.close();

Review Comment:
   It is, but it would be more consistent to use `future.channel().close()` in this case.
   
   One detail is that in Netty 4+, the listeners get executed in the event loop. Explained in https://netty.io/wiki/new-and-noteworthy-in-4.0.html#well-defined-thread-model .
   > The ChannelFutureListeners added to ChannelFuture are always invoked by the EventLoop thread assigned to the future's associated Channel.
   However calling `ctx.close()` is also safe outside the event loop so that wouldn't make a difference in this case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org