Skip to content

Commit

Permalink
[Broker/Client] Close connection if a ping or pong message cannot be …
Browse files Browse the repository at this point in the history
…sent (apache#15382)

* [Broker/Client] Close connection if a ping message cannot be sent

- the connection should be closed if a ping message cannot be sent

* Handle write errors for pong messages

(cherry picked from commit 2ddef95)
  • Loading branch information
lhotari committed Apr 29, 2022
1 parent 4621ca6 commit c0bf8f0
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ final protected void handlePing(CommandPing ping) {
if (log.isDebugEnabled()) {
log.debug("[{}] Replying back to ping message", ctx.channel());
}
ctx.writeAndFlush(Commands.newPong());
ctx.writeAndFlush(Commands.newPong())
.addListener(future -> {
if (!future.isSuccess()) {
log.warn("[{}] Forcing connection to close since cannot send a pong message.",
ctx.channel(), future.cause());
ctx.close();
}
});
}

@Override
Expand All @@ -104,7 +111,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();
}
});
} else {
if (log.isDebugEnabled()) {
log.debug("[{}] Peer doesn't support keep-alive", ctx.channel());
Expand Down

0 comments on commit c0bf8f0

Please sign in to comment.