paho.mqtt.android
paho.mqtt.android copied to clipboard
Cannot properly close and restart connection
Please fill out the form below before submitting, thank you!
- [x] Bug exists Release Version 1.1.1 (Java Repository Master Branch)
- [x] Bug exists in Snapshot Version 1.1.2-SNAPSHOT (Android Service Repository Master Branch) *I can try thi
- [ ] Bug is just in the Sample Application.
Android API Version Bug Seen on: Observed on API 21, API 23 and API 25 (Wear 2.0 Preview 5)
Android Version Bug Seen on: Observed on Android 5.0, 6.0.1 and 7.1.1 (Wear 2.0 Preview 5)
Please also check that if you have found the bug in the Release version (1.1.1) that you check that it also exists in the Snapshot (1.1.2-SNAPSHOT) before raising a bug.
Description of Bug:
I think this could have something to do with Issues like #5 but I'm not 100% sure about that.
In my scenario, an initial connection can fail and the user can change the connection details, which means that I have to create a new instance of the MqttAndroidClient. It seems, however, that after creating a new client, everything get's called twice (or three or four times, depending on how often I tried to connect), which can lead to serious problems, including messages sent multiple times after a successful connect.
I tried to disconnect (if connected) and close the old client in hope that it clears the service, but to no avail.
Here is the code I'm using to reproduce the error:
public void connect(String host, String username, char[] password) throws MqttException {
Timber.d("connect!");
if (isConnected()) {
return;
}
if (client != null) {
if (client.isConnected())
client.disconnect(); // This should be unreachable but is included to be sure
client.close(); // This seems to close the comms of the service forever, but if I omit this, the error still occurs.
}
client = createNewClient(host);
client.setTraceEnabled(true);
client.setTraceCallback(new TraceHandler());
options.setUserName(username);
options.setPassword(password);
try {
client.setCallback(new MyMqttCallback());
client.connect(options).setActionCallback(new IMqttActionListener() {
@Override
public void onSuccess(final IMqttToken asyncActionToken) {
markConnected();
}
@Override
public void onFailure(final IMqttToken asyncActionToken, final Throwable exception) {
markConnectionAbort(exception);
}
});
} catch (MqttException e) {
markConnectionAbort(e);
}
}
public MqttAndroidClient createNewClient(String host) {
// It is assumed that the applicationContext and deviceId are fields of the class
return new MqttAndroidClient(applicationContext, host, deviceId);
}
The log output contains German exception messages, but they describe that for the first connection, the connect timed out, and every other attempt fails because the client is closed (at org.eclipse.paho.client.mqttv3.MqttAsyncClient.connect(MqttAsyncClient.java:539)). If I remove the client.close() statement, the other errors are because of Timeouts, too.
Console Log output (if available):
The log starts after the first connect attempt was started, with the first message that indicates a connection failure. The occurring exceptions are printed by the markConnectionAbort-method that is called from the action-callback.
02-03 10:42:21.540 22461-22461/app E/MqttClient$TraceHandler: MqttConnection: connect fail, call connect to reconnect.reason:MqttException
02-03 10:42:21.549 22461-22461/app E/MqttClient: markConnectionAbort: Der Verbindungsaufbau ist wegen eines Fehlers abgebrochen. Es wird nicht erneut versucht, sich wiederzuverbinden.
MqttException (0) - java.net.SocketTimeoutException: connect timed out
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:664)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:334)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:196)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356)
at java.net.Socket.connect(Socket.java:605)
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:70)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650)
at java.lang.Thread.run(Thread.java:761)
02-03 10:42:49.444 22461-22461/app D/MqttClient: connect!
02-03 10:42:49.469 22461-22461/app D/MqttClient$TraceHandler: MqttConnection: close()
02-03 10:42:49.492 22461-22461/app D/MqttClient$TraceHandler: DatabaseMessageStore: clearArrivedMessages: clearing the table of tcp://10.1.1.42:581cc6d21b336d4e:app messages
02-03 10:42:49.493 22461-22461/app D/MqttClient$TraceHandler: DatabaseMessageStore: clearArrivedMessages: clearing the table of tcp://10.1.1.42:581cc6d21b336d4e:app messages
02-03 10:42:49.494 22461-22461/app D/MqttClient$TraceHandler: DatabaseMessageStore: clearArrivedMessages: rows affected = 0
02-03 10:42:49.495 22461-22461/app D/MqttClient$TraceHandler: DatabaseMessageStore: clearArrivedMessages: rows affected = 0
02-03 10:42:49.497 22461-22461/app D/MqttClient$TraceHandler: MqttConnection: Connecting {tcp://10.1.1.42} as {581cc6d21b336d4e}
02-03 10:42:49.498 22461-22461/app D/MqttClient$TraceHandler: MqttConnection: Connecting {tcp://10.1.1.42} as {581cc6d21b336d4e}
02-03 10:42:49.499 22461-22461/app D/MqttClient$TraceHandler: MqttConnection: myClient != null and the client is not connected
02-03 10:42:49.503 22461-22461/app D/MqttClient$TraceHandler: MqttConnection: myClient != null and the client is not connected
02-03 10:42:49.504 22461-22461/app D/MqttClient$TraceHandler: MqttConnection: Do Real connect!
02-03 10:42:49.506 22461-22461/app D/MqttClient$TraceHandler: MqttConnection: Do Real connect!
02-03 10:42:49.507 22461-22461/app E/MqttClient$TraceHandler: MqttConnection: Exception occurred attempting to connect: Client ist geschlossen
02-03 10:42:49.508 22461-22461/app E/MqttClient$TraceHandler: MqttConnection: Exception occurred attempting to connect: Client ist geschlossen
02-03 10:42:49.513 22461-22461/app E/MqttClient: markConnectionAbort: Der Verbindungsaufbau ist wegen eines Fehlers abgebrochen. Es wird nicht erneut versucht, sich wiederzuverbinden.
Client ist geschlossen (32111)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.connect(MqttAsyncClient.java:539)
at org.eclipse.paho.android.service.MqttConnection.connect(MqttConnection.java:282)
at org.eclipse.paho.android.service.MqttService.connect(MqttService.java:329)
at org.eclipse.paho.android.service.MqttAndroidClient.doConnect(MqttAndroidClient.java:467)
at org.eclipse.paho.android.service.MqttAndroidClient.access$200(MqttAndroidClient.java:76)
at org.eclipse.paho.android.service.MqttAndroidClient$MyServiceConnection.onServiceConnected(MqttAndroidClient.java:115)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1453)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1481)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
02-03 10:42:49.538 22461-22461/app E/MqttClient: markConnectionAbort: Der Verbindungsaufbau ist wegen eines Fehlers abgebrochen. Es wird nicht erneut versucht, sich wiederzuverbinden.
Client ist geschlossen (32111)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.connect(MqttAsyncClient.java:539)
at org.eclipse.paho.android.service.MqttConnection.connect(MqttConnection.java:282)
at org.eclipse.paho.android.service.MqttService.connect(MqttService.java:329)
at org.eclipse.paho.android.service.MqttAndroidClient.doConnect(MqttAndroidClient.java:467)
at org.eclipse.paho.android.service.MqttAndroidClient.access$200(MqttAndroidClient.java:76)
at org.eclipse.paho.android.service.MqttAndroidClient$MyServiceConnection.onServiceConnected(MqttAndroidClient.java:115)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1453)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1481)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
02-03 10:43:00.956 22461-22461/app D/MqttClient: cleanObservables: connect!
02-03 10:43:00.979 22461-22461/app D/MqttClient$TraceHandler: MqttConnection: close()
02-03 10:43:00.981 22461-22461/app D/MqttClient$TraceHandler: MqttConnection: close()
02-03 10:43:00.996 22461-22461/app D/MqttClient$TraceHandler: DatabaseMessageStore: clearArrivedMessages: clearing the table of tcp://10.1.1.42:581cc6d21b336d4e:app messages
02-03 10:43:00.997 22461-22461/app D/MqttClient$TraceHandler: DatabaseMessageStore: clearArrivedMessages: clearing the table of tcp://10.1.1.42:581cc6d21b336d4e:app messages
02-03 10:43:00.998 22461-22461/app D/MqttClient$TraceHandler: DatabaseMessageStore: clearArrivedMessages: clearing the table of tcp://10.1.1.42:581cc6d21b336d4e:app messages
02-03 10:43:00.999 22461-22461/app D/MqttClient$TraceHandler: DatabaseMessageStore: clearArrivedMessages: rows affected = 0
02-03 10:43:01.000 22461-22461/app D/MqttClient$TraceHandler: DatabaseMessageStore: clearArrivedMessages: rows affected = 0
02-03 10:43:01.000 22461-22461/app D/MqttClient$TraceHandler: DatabaseMessageStore: clearArrivedMessages: rows affected = 0
02-03 10:43:01.001 22461-22461/app D/MqttClient$TraceHandler: MqttConnection: Connecting {tcp://10.1.1.42} as {581cc6d21b336d4e}
02-03 10:43:01.006 22461-22461/app D/MqttClient$TraceHandler: MqttConnection: Connecting {tcp://10.1.1.42} as {581cc6d21b336d4e}
02-03 10:43:01.007 22461-22461/app D/MqttClient$TraceHandler: MqttConnection: Connecting {tcp://10.1.1.42} as {581cc6d21b336d4e}
02-03 10:43:01.008 22461-22461/app D/MqttClient$TraceHandler: MqttConnection: myClient != null and the client is not connected
02-03 10:43:01.009 22461-22461/app D/MqttClient$TraceHandler: MqttConnection: myClient != null and the client is not connected
02-03 10:43:01.010 22461-22461/app D/MqttClient$TraceHandler: MqttConnection: myClient != null and the client is not connected
02-03 10:43:01.016 22461-22461/app D/MqttClient$TraceHandler: MqttConnection: Do Real connect!
02-03 10:43:01.017 22461-22461/app D/MqttClient$TraceHandler: MqttConnection: Do Real connect!
02-03 10:43:01.018 22461-22461/app D/MqttClient$TraceHandler: MqttConnection: Do Real connect!
02-03 10:43:01.019 22461-22461/app E/MqttClient$TraceHandler: MqttConnection: Exception occurred attempting to connect: Client ist geschlossen
02-03 10:43:01.023 22461-22461/app E/MqttClient$TraceHandler: MqttConnection: Exception occurred attempting to connect: Client ist geschlossen
02-03 10:43:01.024 22461-22461/app E/MqttClient$TraceHandler: MqttConnection: Exception occurred attempting to connect: Client ist geschlossen
02-03 10:43:01.028 22461-22461/app E/MqttClient: markConnectionAbort: Der Verbindungsaufbau ist wegen eines Fehlers abgebrochen. Es wird nicht erneut versucht, sich wiederzuverbinden.
Client ist geschlossen (32111)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.connect(MqttAsyncClient.java:539)
at org.eclipse.paho.android.service.MqttConnection.connect(MqttConnection.java:282)
at org.eclipse.paho.android.service.MqttService.connect(MqttService.java:329)
at org.eclipse.paho.android.service.MqttAndroidClient.doConnect(MqttAndroidClient.java:467)
at org.eclipse.paho.android.service.MqttAndroidClient.access$200(MqttAndroidClient.java:76)
at org.eclipse.paho.android.service.MqttAndroidClient$MyServiceConnection.onServiceConnected(MqttAndroidClient.java:115)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1453)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1481)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
02-03 10:43:01.049 22461-22461/app E/MqttClient: markConnectionAbort: Der Verbindungsaufbau ist wegen eines Fehlers abgebrochen. Es wird nicht erneut versucht, sich wiederzuverbinden.
Client ist geschlossen (32111)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.connect(MqttAsyncClient.java:539)
at org.eclipse.paho.android.service.MqttConnection.connect(MqttConnection.java:282)
at org.eclipse.paho.android.service.MqttService.connect(MqttService.java:329)
at org.eclipse.paho.android.service.MqttAndroidClient.doConnect(MqttAndroidClient.java:467)
at org.eclipse.paho.android.service.MqttAndroidClient.access$200(MqttAndroidClient.java:76)
at org.eclipse.paho.android.service.MqttAndroidClient$MyServiceConnection.onServiceConnected(MqttAndroidClient.java:115)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1453)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1481)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
02-03 10:43:01.077 22461-22461/app E/MqttClient: markConnectionAbort: Der Verbindungsaufbau ist wegen eines Fehlers abgebrochen. Es wird nicht erneut versucht, sich wiederzuverbinden.
Client ist geschlossen (32111)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.connect(MqttAsyncClient.java:539)
at org.eclipse.paho.android.service.MqttConnection.connect(MqttConnection.java:282)
at org.eclipse.paho.android.service.MqttService.connect(MqttService.java:329)
at org.eclipse.paho.android.service.MqttAndroidClient.doConnect(MqttAndroidClient.java:467)
at org.eclipse.paho.android.service.MqttAndroidClient.access$200(MqttAndroidClient.java:76)
at org.eclipse.paho.android.service.MqttAndroidClient$MyServiceConnection.onServiceConnected(MqttAndroidClient.java:115)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1453)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1481)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Now the real question
How can I reset the service so that nothing gets called twice? Closing the client seems to end things for all future clients, too.
No feedback? And what does the triage tag mean?
I am also facing same issue, when we change the connection details and try to close the previous connection, It's not getting close. If i try disconnectForcibly() then i am getting UnsupportedOperationException(). Please tell me how do I completely close the connection in order to create a new connection. Thank you!
Identical issue over here. Has there been any progress – either solution or workaround? In my scenario, I need the client to connect to either a local URI (internal network) or an external URI, depending if the device is connecting via Wifi or mobile network, so the system can operate (locally) even when cut of from the internet. So far my attempts and problems were the same as described by @looperhacks but if anyone found a more 'creative' approach that solves this issues it would be amazing to see it shared here! Thanks!
I am now calling unregisterResources on the client before closing it. I'm not sure that it solves everything, it has been a while since I touched that code.
Note that unregisterResources is not available in IMqttAsyncClient but is only declared in MqttAndroidClient.
sandbender3000 [email protected] schrieb am Mi., 30. Aug. 2017 um 11:40 Uhr:
Identical issue over here. Has there been any progress – either solution or workaround? In my scenario, I need the client to connect to either a local URI (internal network) or an external URI, depending if the device is connecting via Wifi or mobile network, so the system can operate (locally) even when cut of from the internet. So far my attempts and problems were the same as described by @looperhacks https://github.com/looperhacks but if anyone found a more 'creative' approach that solves this issues it would be amazing to see those shared here! Thanks!
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/eclipse/paho.mqtt.android/issues/178#issuecomment-325939391, or mute the thread https://github.com/notifications/unsubscribe-auth/AAlhEWqwXSoz1yKxKSYvrbGBP9m-cfYsks5sdS4ggaJpZM4L2JTE .
I too was getting exceptions when I disconnect. I thought I was unsubscribing from all subscriptions before calling disconnect but I had a bug and that wasn't actually happening. After fixing it, when I call disconnect, it does actually disconnect. The problem now is that if I wait with a timeout, the timeout always occurs, even though the connection is actually closed. So bottom line is I get an exception every time, but at least now it actually does disconnect. I wish there was some documentation that explained the proper way to disconnect. Seems like this should be a simple thing.
+1
This is also causing Tomcat (to give an example) not to shutdown properly if there is a problem connecting to a MQTT server, it would be really nice to have this one solved as it can mess up shutdown life cycles.
Edit: By mess up I meant that it is not letting the JVM shutdown so some thread is probably on a weird state after unsuccessful connection attempt.
I have the same issue, but in a simpler scenario. I am not even trying to switch between channels: link 1 The problem seems to be that disconnect() does not do its job immediately, but waits for the message pipeline to dry out: link 2 There must be a way to queue up the disconnect request, and revoke it if the same client ID sends a freesh connect request.
I had the same issue because I didn't call client.disconnect() AFTER client.close(). So this order works in my case:
mqttAndroidClient.unregisterResources();
mqttAndroidClient.close();
mqttAndroidClient.disconnect();
mqttAndroidClient.setCallback(null);
mqttAndroidClient = null
Reproduces on Android 10, when even using the below teardown ` try {
unsubscribe("testTopic");
mqttClient.unregisterResources();
mqttClient.close();
mqttClient.disconnect();
mqttClient.setCallback(null);
mqttClient = null;
} catch (MqttException e) {
Timber.e( e.toString());
}
`
still gives the error
2020-08-24 16:32:18.155 12721-12721/com.android.testapp I/MqttService: Mqtt destroy 2020-08-24 16:32:18.219 12721-12721/com.android.testapp E/ActivityThread: Service org.eclipse.paho.android.service.MqttService has leaked IntentReceiver org.eclipse.paho.android.service.AlarmPingSender$AlarmReceiver@cf14ad4 that was originally registered here. Are you missing a call to unregisterReceiver()? android.app.IntentReceiverLeaked: Service org.eclipse.paho.android.service.MqttService has leaked IntentReceiver org.eclipse.paho.android.service.AlarmPingSender$AlarmReceiver@cf14ad4 that was originally registered here. Are you missing a call to unregisterReceiver()? at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:1707) at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:1438) at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1576) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1549) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1537) at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:641) at org.eclipse.paho.android.service.AlarmPingSender.start(AlarmPingSender.java:74) at org.eclipse.paho.client.mqttv3.internal.ClientState.connected(ClientState.java:1134) at org.eclipse.paho.client.mqttv3.internal.ClientState.notifyReceivedAck(ClientState.java:970) at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:128) at java.lang.Thread.run(Thread.java:919)
Hello all,
I have just hit this same problem. I use an MQTT client in an Android app that switches between two different brokers. I see that for every round trip of switching between the brokers (Broker A, Broker B, back to Broker A) I see that I get one additional subscribe. I implemented the suggested solution by @chris-hbrch but I see the same problems as @aristotelis-vryonidis Below you can see the flow og my connects.
- Connect to Broker A (Local Mosquitto broker)
- Connect to Broker B (AWS IoT Broker)
- Switch back to Broker A
Now receive all messages double up. For each cycle I do of this, I get an additional subscribe.
I use cleanSession for all connect attempts.
Reproduz no Android 10, mesmo usando o seguinte desmontagem ` try {
unsubscribe("testTopic"); mqttClient.unregisterResources(); mqttClient.close(); mqttClient.disconnect(); mqttClient.setCallback(null); mqttClient = null; } catch (MqttException e) { Timber.e( e.toString()); }
`
ainda dá o erro
2020-08-24 16:32:18.155 12721-12721/com.android.testapp I/MqttService: Mqtt destroy 2020-08-24 16:32:18.219 12721-12721/com.android.testapp E/ActivityThread: Service org.eclipse.paho.android.service.MqttService has leaked IntentReceiver org.eclipse.paho.android.service.AlarmPingSender$AlarmReceiver@cf14ad4 that was originally registered here. Are you missing a call to unregisterReceiver()? android.app.IntentReceiverLeaked: Service org.eclipse.paho.android.service.MqttService has leaked IntentReceiver org.eclipse.paho.android.service.AlarmPingSender$AlarmReceiver@cf14ad4 that was originally registered here. Are you missing a call to unregisterReceiver()? at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:1707) at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:1438) at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1576) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1549) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1537) at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:641) at org.eclipse.paho.android.service.AlarmPingSender.start(AlarmPingSender.java:74) at org.eclipse.paho.client.mqttv3.internal.ClientState.connected(ClientState.java:1134) at org.eclipse.paho.client.mqttv3.internal.ClientState.notifyReceivedAck(ClientState.java:970) at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:128) at java.lang.Thread.run(Thread.java:919)
Are you using Keep Alive?
Set keepAliveInterval to 0 in MqttConnectOptions, I didn't suffer that failure you mentioned, apparently it's working here!
MqttConnectOptions().apply {
userName = BROKER_USER
password = BROKER_PASSWORD.toCharArray()
mqttVersion = MqttConnectOptions.MQTT_VERSION_3_1
serverURIs = arrayOf(BROKER_URI)
connectionTimeout = 5
maxReconnectDelay = 15000
isCleanSession = true
isAutomaticReconnect = true
keepAliveInterval = 0
}
This is the process I'm going through to close the connection.
_client?.apply {
unregisterResources()
close()
disconnect(0)
setCallback(null)
}
_client = null
I noticed that it generates several Threads when I disconnect, but they are terminated soon after.