eclipse / paho.mqtt.java

Eclipse Paho Java MQTT client library. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
2.12k stars 884 forks source link

Possible bug for replacing clean with another clean session? #601

Open thashimalayaratnam opened 5 years ago

thashimalayaratnam commented 5 years ago

In https://github.com/eclipse/paho.mqtt.java/blob/master/org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal/CommsReceiver.java#L177-L182 we throw exception if not in isDisconnecting() state. I am seeing transient EOF Exceptions thrown from aforementioned line when I re-connect a clean session using the same MqttClient object. I.e.

MqttClient subscriber = createSyncMqttClient(subscriberClientId);
subscriber.connect(createConnectOptionsWithCleanSession(true));
subscriber.subscribe(topic, 1);
subscriber.disconnect();
// EOF Exception thrown transiently upon executing this line
IMqttToken token = subscriber.connectWithResult(createConnectOptionsWithCleanSession(true));

I suspect this is is because the broker is sending EOF but since we are trying to connect back that exception is thrown? Is this possible? Thanks in advance.

I notice if I use a different MqttClient to re-connect then this won't happen.

icraggs commented 5 years ago

It's one of the characteristics of MQTT that there is no acknowledgement to the disconnect request, so the timing of reconnection may be tricky.

Having said that, this might be due to issue #402, which I'll be looking at soon.