Browse Source

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.
pull/364/merge
Andy Wilkinson 13 years ago committed by Rossen Stoyanchev
parent
commit
6679feb77b
  1. 12
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java

12
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java

@ -438,7 +438,12 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler @@ -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 @@ -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());
}
}
});

Loading…
Cancel
Save