I'm using MQTT in an android application, using the latest jar as found on the Eclipse Paho page.
I'm manually checking the connection by sending occasional publishes under a QOS of 1, and if it's not delivered under a certain timeout I disconnect MQTT and reconnect. When the data connection is lost then regained I also force a reconnect.
The issue is that the disconnect method hangs the thread and never completes - even with a zero or negative timeout. It's supposed to have an internal timeout of 30 seconds but it goes long past this and never completes.
The MqttClient object needs to be disconnected otherwise it sits in the background chewing up data. What I'm now doing is spinning off a seperate thread to disconnect MQTT then creating a new MqttClient entirely. It stops using data but it's a bad solution as the new thread just hangs instead.
Any ideas?
Edit: On further investigation it seems to be blocking on attempting to stop CommsReceiver at line 70:
public void stop() throws IOException {
synchronized (lifecycle) {
//@TRACE 850=stopping receiver
trace.trace(Trace.FINE,850);
if (running) {
running = false;
try {
//@TRACE 851=stop: wait on lifecycle
trace.trace(Trace.FINE,851);
// Wait for the thread to finish.
lifecycle.wait(); // THREAD HANGS //
}
catch (InterruptedException ex) {
}
}
}
}
The problem is due to a timing window in the stable version of the paho client, if you use the code in the develop branch of the paho repository. You shouldn't come across this problem because it is marked as fixed in this bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=394066 although its not the stable branch I have found the develop branch to be reliable.
There is a bug filed here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=394066 (probably by the OP of this question, info for @Vipul). The status says resolved so see when the new JAR is available with the fix and use that
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With