smartrent / jackalope

An opinionated MQTT client library based on Tortoise MQTT
Apache License 2.0
28 stars 5 forks source link

Make sure we resubscribe to topics we were subscribed on reconnect #11

Closed gausby closed 3 years ago

gausby commented 3 years ago

When Tortoise emit a terminating, terminated, or down message we will take what ever was in our Hare subscription list and place subscription orders in the work list. Once we are back online we will start processing the work list ensuring we are subscribed to the topic filters (note that the MQTT session state should take care of this, but this is done in Hare to ensure a consistent view of the world).

This code is mostly moved from the callback that handled the Hare.reconnect; the reconnect path will still work as previously as it will receive the down messages during the reconnect flow.

This solution should be more robust and shouldn't drop subscriptions—unless there is some crazy race condition, but I think it is very unlikely.