paho.mqtt.java icon indicating copy to clipboard operation
paho.mqtt.java copied to clipboard

Timeout for waiting for CONNACK

Open bergowic opened this issue 7 years ago • 5 comments
trafficstars

  • [x] Bug exists Release Version 1.2.0 ( Master Branch)

After establishing a TCP connection to a broker and sending the CONNECT message, the client will wait for a CONNACK message indefinitely. There should be a timeout for not receiving the CONNACK message within a specific period.

bergowic avatar Apr 06 '18 13:04 bergowic

To make it more precise: I have a problem when I try connect to a TCP server which does not support MQTT. The server does not close the connection and the client waits for a CONNACK. I did also not figure out to stop the client in any wait, since close throws an exception and disconnect never terminates.

bergowic avatar Apr 10 '18 12:04 bergowic

Hi,

You when you use connect, you will get a IMqttToken back, if you then call waitForCompletion(<time in milliseconds>);, then it will wait for the client to either complete the connection, or for the timeout, whichever is first.

Then you can simply check isConnected() on the client and you will be able to tell if it failed or succeeded.

jpwsutton avatar Apr 17 '18 13:04 jpwsutton

I'm using callbacks when connecting, but they will never be called due to this problem. I'd prefer to not block on waitForCompletion().

pschichtel avatar Sep 18 '18 18:09 pschichtel

Concerning this issue, the absence of timeout for connack is especially troublesome when it comes to reconnection. That is, we don't have to access to IMqttToken at the time of recconection. Do you guys have ideas to deal with connack timeout properly for reconnection?

bananaumai avatar Dec 10 '19 05:12 bananaumai

Relates to: https://github.com/eclipse/paho.mqtt.java/issues/856

powturns avatar Jun 11 '21 15:06 powturns