Skip to content

Commit ec51902

Browse files
hmvpjpwsutton
authored andcommitted
Make sure the client does not enter a disconnect/connect loop (#317)
When the client recieves an ack for a publish is does not know about it will disconnect and reconnect receiving the same ack again. This can only be fixed by using clean session which is not always desirable. This patch makes sure the client ignores the message so that the flow can continue Signed-off-by: Hmvp <github@hmvp.nl>
1 parent 1a4ce61 commit ec51902

1 file changed

Lines changed: 8 additions & 0 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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import org.eclipse.paho.client.mqttv3.MqttToken;
2323
import org.eclipse.paho.client.mqttv3.internal.wire.MqttAck;
2424
import org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream;
25+
import org.eclipse.paho.client.mqttv3.internal.wire.MqttPubAck;
26+
import org.eclipse.paho.client.mqttv3.internal.wire.MqttPubComp;
27+
import org.eclipse.paho.client.mqttv3.internal.wire.MqttPubRec;
2528
import org.eclipse.paho.client.mqttv3.internal.wire.MqttWireMessage;
2629
import org.eclipse.paho.client.mqttv3.logging.Logger;
2730
import org.eclipse.paho.client.mqttv3.logging.LoggerFactory;
@@ -124,6 +127,11 @@ public void run() {
124127
// can occur before request processing is complete if not!
125128
clientState.notifyReceivedAck((MqttAck)message);
126129
}
130+
} else if(message instanceof MqttPubRec || message instanceof MqttPubComp || message instanceof MqttPubAck) {
131+
//This is an ack for a message we no longer have a ticket for.
132+
//This probably means we already received this message and it's being send again
133+
//because of timeouts, crashes, disconnects, restarts etc.
134+
//It should be safe to ignore these unexpected messages.
127135
} else {
128136
// It its an ack and there is no token then something is not right.
129137
// An ack should always have a token assoicated with it.

0 commit comments

Comments
 (0)