eclipse-paho / eclipse-paho/paho.mqtt.java
MqttAsyncClient trying to reconnect after explicitly disconnected
- Dominant language
- Java
- Stars
- 2.3k
- Forks
- 919
- PR merge metrics
- No merged PRs in 30d
Description
Please fill out the form below before submitting, thank you!
- [X ] Bug exists Release Version 1.2.0 ( Master Branch)
- [X] Bug exists in MQTTv3 Client on Snapshot Version 1.2.1-SNAPSHOT (Develop Branch)
- [ ] Bug exists in MQTTv5 Client on Snapshot Version 1.2.1-SNAPSHOT (Develop Branch)
If a MqttAsyncClient is created **with reconnect option** and after used, it is closed with **disconnectForcibly**, an exception is thrown because it is trying to reconnect.
13:16:19,196 FINE [org.eclipse.paho.client.mqttv3.MqttAsyncClient] (Timer-11) 046aea33-627e-43f3-900b-72f5ae05b98d: exception: Client is closed (32111)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.connect(MqttAsyncClient.java:608)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.attemptReconnect(MqttAsyncClient.java:1177)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.access$2(MqttAsyncClient.java:1172)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient$ReconnectTask.run(MqttAsyncClient.java:1253)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
My expectation is that this client should try to reconnect if and only if is has been unexpectedly disconnected, but if it has been explicitly disconnected, it shouldn't try to reconnect.
I have tried with version 1.1.1, but looking at the source code, the issue is still present in latest code, because
comms.setReconnectCallback(new MqttReconnectCallback(automaticReconnect));
has no way to "unset" the reconnect callback after created.
Contributor guide
Research direction
Start in MqttAsyncClient.java at disconnectForcibly, attemptReconnect, ReconnectTask.run, and the reconnect callback setup. Trace how explicit disconnection differs from an unexpected disconnect, then verify that an explicitly disconnected client no longer attempts reconnection while unexpected disconnections still can trigger it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100