fusesource / mqtt-client

A Java MQTT Client
http://mqtt-client.fusesource.org/
Apache License 2.0
1.27k stars 369 forks source link

about auto-connection issues #48

Open luchec opened 8 years ago

luchec commented 8 years ago

i use "mqtt.setReconnectAttemptsMax(-1)" to set the program auto connect in disconnection,but when i turn off wifi,maybe have passed 30s ,fusesource mqtt-client callback disconnect notification for。 and then turn on again, maybe few seconds,mqtt-client auto connecting ,but appear twice connect,it is cause a loop that connected and disconnect。could somebody help me? thanks

lopatoid commented 8 years ago

I have the same problem, but I find it very hard to reproduce. Sometimes it's OK, but sometimes it just goes into loop of connects and disconnects, then program crashes with NPE or OOM. BTW, I am using the Callback/Continuation Passing based API on Android. And you, @luchec ?

lopatoid commented 8 years ago

OK, definitely a bug. I've found a way to get a good percent of reproducibility. 1) Run your program. Then on host with MQTT server (I use mosquitto) execute:

sudo iptables -A INPUT -p tcp --dport 1883 -j DROP

wait up to 30 seconds... than:

sudo iptables -D INPUT -p tcp -m tcp --dport 1883 -j DROP

And voila!

If using blocking connection (for simplicity I even started sample program on localhost):

Exception in thread "hawtdispatch-DEFAULT-2" java.lang.NullPointerException
    at org.fusesource.mqtt.client.CallbackConnection$7.run(CallbackConnection.java:414)
    at org.fusesource.hawtdispatch.transport.HeartBeatMonitor$3.run(HeartBeatMonitor.java:83)
    at org.fusesource.hawtdispatch.transport.HeartBeatMonitor$1.run(HeartBeatMonitor.java:62)
    at org.fusesource.hawtdispatch.internal.SerialDispatchQueue.run(SerialDispatchQueue.java:100)
    at org.fusesource.hawtdispatch.internal.pool.SimpleThread.run(SimpleThread.java:77)

If using Callback/Continuation Passing based API, I see this loop of connects and disconnects and they occurs on different hawtdispatch threads. Like this:

hawtdispatch-DEFAULT-3 : connected
hawtdispatch-DEFAULT-1: connected
hawtdispatch-DEFAULT-1: disconnected
hawtdispatch-DEFAULT-4: connected
hawtdispatch-DEFAULT-2: connected
hawtdispatch-DEFAULT-2: disconnected
... etc etc

@chirino , is there any workaround?

Monachus commented 8 years ago

@looluo you know if they are going to merge this back at fuse-source?

MarcoPOLOFXH commented 7 years ago

@chirino Still tracking this issue, would like to see @looluo's merged at fuse-source or for it to be otherwise addressed.