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
I investigated a blocking on shutdown situation in our code base. We are using the MQTTAsync api of the paho version 1.3.12 currently on both windows and unix-like OS-s.
Scenario
We have a publisher.
We initiate a shutdown to our application which in the process calls MQTTAsync_disconnect. The onSuccess5 and onFailure5 callbacks are set and will send a signal (depending on OS using mutex for linux and SetEvent from synchapi for windows) to the main thread
The main thread waits for a signal (without timeout). The callback are executed/handled on other threads.
after the signal is fired it will call MQTTAsync_destroy and finish
Our problem come into play when before the signal fired (step 4.) the application loses the connection to the broker and we are in a state where there are some messages left in queue for publishing, already called MQTTAsync_sendMessage with them, but we also called the MQTTAsync_disconnect.
After a bit of investigation/debugging I found the paho will skip the client if it's not connected and the first command from it is a publish, only processes connect/disconnect commands if those are at the start of the command queue other wise skip every command from that client. So in our case we have N publish commands and 1 disconnect, the paho will check the first publish see the client is disconnected and skip all N publish plus the 1 disconnect.
Questions
Is it intended on the paho.mqtt.c part to wait for all the queued messages to be published even if the client wants to disconnect and lost connection?
Is it safe to call the MQTTAsync_destroy even if the disconnect callbacks are not called yet (neither fail nor success)? If it's okay, we could just wait with timeout and if the disconnect did not succeeded or failed call the destroy anyway and handle the failures via the callback set for the publishing. Could there be unseen consequences?
Of course if there is a reconnect paho would publish all the messages and process the disconnect and the application could shutdown gracefully.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Context
I investigated a blocking on shutdown situation in our code base. We are using the MQTTAsync api of the paho version 1.3.12 currently on both windows and unix-like OS-s.
Scenario
MQTTAsync_disconnect
. TheonSuccess5
andonFailure5
callbacks are set and will send a signal (depending on OS using mutex for linux and SetEvent from synchapi for windows) to the main threadOur problem come into play when before the signal fired (step 4.) the application loses the connection to the broker and we are in a state where there are some messages left in queue for publishing, already called
MQTTAsync_sendMessage
with them, but we also called theMQTTAsync_disconnect
.After a bit of investigation/debugging I found the paho will skip the client if it's not connected and the first command from it is a publish, only processes connect/disconnect commands if those are at the start of the command queue other wise skip every command from that client. So in our case we have N publish commands and 1 disconnect, the paho will check the first publish see the client is disconnected and skip all N publish plus the 1 disconnect.
Questions
Of course if there is a reconnect paho would publish all the messages and process the disconnect and the application could shutdown gracefully.
Any help is appreciated!
Beta Was this translation helpful? Give feedback.
All reactions