You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using update connect options callback (set by MQTTAsync_setUpdateConnectOptions), this callback is fired to often: once before reconnect (that is ok) and the second time after 3 secons (that is not correct). If there is the log informing user about reconnect in the callback user gets wrongly informed in case of this extra call.
The problem happens because MQTTAsync_startConnectRetry (where lastConnectionFailedTime and currentInterval are set) is called very late after MQTTProtocol_connect. This is because socket is not ready for some time (> 3 second most of the time) for checking of TCP connection completion. In meantime MQTTAsync_checkTimeouts function body is executed every 3 seconds, keeping eye on the reconnection time. So when time to reconnect comes (based on lastConnectionFailedTime and currentInterval), update connect options callback (the one set by call MQTTAsync_setUpdateConnectOptions) is fired and reconnect initialized (connect queued and executed (MQTTAsync_processCommand)) but then fired again after 3 seconds because lastConnectionFailedTime won't make to be set to new value. Usually the second call of the callback is not followed by real connect because connect_state is usually TCP_IN_PROGRESS, but I noticed once situation that it was no the case and the second connect was attempted.
To Reproduce
Set automaticReconnect connection option and set callback using MQTTAsync_setUpdateConnectOptions
Describe the bug
When using update connect options callback (set by MQTTAsync_setUpdateConnectOptions), this callback is fired to often: once before reconnect (that is ok) and the second time after 3 secons (that is not correct). If there is the log informing user about reconnect in the callback user gets wrongly informed in case of this extra call.
The problem happens because MQTTAsync_startConnectRetry (where lastConnectionFailedTime and currentInterval are set) is called very late after MQTTProtocol_connect. This is because socket is not ready for some time (> 3 second most of the time) for checking of TCP connection completion. In meantime MQTTAsync_checkTimeouts function body is executed every 3 seconds, keeping eye on the reconnection time. So when time to reconnect comes (based on lastConnectionFailedTime and currentInterval), update connect options callback (the one set by call MQTTAsync_setUpdateConnectOptions) is fired and reconnect initialized (connect queued and executed (MQTTAsync_processCommand)) but then fired again after 3 seconds because lastConnectionFailedTime won't make to be set to new value. Usually the second call of the callback is not followed by real connect because connect_state is usually TCP_IN_PROGRESS, but I noticed once situation that it was no the case and the second connect was attempted.
To Reproduce
Set automaticReconnect connection option and set callback using MQTTAsync_setUpdateConnectOptions
My example using paho cpp:
Expected behavior
Update connect options callback is fired once per reconnect attempt.
Screenshots
N/A
Log files
N/A
** Environment (please complete the following information):**
Windows 11
Additional context
N/A
The text was updated successfully, but these errors were encountered: