eclipse / paho.golang

Go libraries
Other
327 stars 92 forks source link

autopaho ConnectRetryDelay not working #213

Closed yokyj closed 9 months ago

yokyj commented 9 months ago

Describe the bug Once the paho.ClientConfig.OnServerDisconnect gets triggered,
autopaho.ClientConfig.OnConnectionUp gets triggered immediately.

To reproduce 1.start a client in the background

  1. start another client using the same clientID, then the broker would disconnect the old connection

Debug output Any debugging output provided by the client code while reproducing the bug (either embedded to link to the output)

Expected behaviour I thought it should wait for ConnectRetryDelay (default by 10s) before it trys reconnecting

Software used:

MattBrittan commented 9 months ago

I thought it should wait for ConnectRetryDelay (default by 10s) before it trys reconnecting

ConnectRetryDelay is the delay between connection retries (i.e. the connection attempt fails so we will retry after ConnectRetryDelay). This only applies up to the point that the connection is established (i.e. the broker sends us a CONNACK); after that point we are establishing a new connection (rather than retrying).

So if the broker sends a valid CONNACK and then immediately drops the connection, autopaho will attempt to establish a new connection immediately (this should be fairly rare; the exception being when two clients are using the same client ID).

It would be possible to change this but it should not be something that happens often in production systems (and in test systems it's quite useful to have the reconnect occur immediately as it alerts you that there is an issue).

Note that starting two instances of autopaho, that connect to the same broker with the same client ID, will cause issues because autopaho will attempt to reconnect automatically so what will happen is: