Skip to content

Commit d7a3bdb

Browse files
author
Ranjan Dasgupta
authored
Merge pull request #727 from ogis-yamazaki/shutdownconnection_called_twice
Fix for issue #726
2 parents fb0ab1b + 6d770e2 commit d7a3bdb

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

  • org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal/CommsReceiver.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,16 @@ public void run() {
186186
catch (IOException ioe) {
187187
//@TRACE 853=Stopping due to IOException
188188
log.fine(CLASS_NAME,methodName,"853");
189-
synchronized (lifecycle) {
190-
target_state = State.STOPPED;
191-
}
192-
// An EOFException could be raised if the broker processes the
193-
// DISCONNECT and ends the socket before we complete. As such,
194-
// only shutdown the connection if we're not already shutting down.
195-
if (!clientComms.isDisconnecting()) {
196-
clientComms.shutdownConnection(token, new MqttException(MqttException.REASON_CODE_CONNECTION_LOST, ioe));
189+
if (target_state != State.STOPPED) {
190+
synchronized (lifecycle) {
191+
target_state = State.STOPPED;
192+
}
193+
// An EOFException could be raised if the broker processes the
194+
// DISCONNECT and ends the socket before we complete. As such,
195+
// only shutdown the connection if we're not already shutting down.
196+
if (!clientComms.isDisconnecting()) {
197+
clientComms.shutdownConnection(token, new MqttException(MqttException.REASON_CODE_CONNECTION_LOST, ioe));
198+
}
197199
}
198200
}
199201
finally {

0 commit comments

Comments
 (0)