提交 6679feb7 编写于 作者: A Andy Wilkinson 提交者: Rossen Stoyanchev

Improve handling of missed heartbeats

Previously, when a broker heartbeat was mnissed, the STOMP connection
would be left in a semi-disconnected state such that, for example, the
read and write idle callbacks would still be active, even though
the underlying TCP connection had been nulled out.

As part of disconnecting the STOMP connection, this commit closes the
underlying TCP connection when a heartbeat's missed which cancels the
read and write idle callbacks. It also now copes with the underlying
TCP connection being null when sending a heartbeat to the broker. This
protects again a race condition between the write idle callback being
fired, such that a heartbeat needs to be sent, and the connection
being nulled out due to it being closed.
上级 bae9134a
......@@ -438,7 +438,12 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
public void setDisconnected() {
this.readyConnection.set(null);
this.connection = null;
TcpConnection<Message<byte[]>, Message<byte[]>> localConnection = this.connection;
if (localConnection != null) {
localConnection.close();
this.connection = null;
}
}
@Override
......@@ -499,7 +504,10 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
@Override
public void run() {
stompConnection.connection.send(MessageBuilder.withPayload(heartbeatPayload).build());
TcpConnection<Message<byte[]>, Message<byte[]>> connection = stompConnection.connection;
if (connection != null) {
connection.send(MessageBuilder.withPayload(heartbeatPayload).build());
}
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册