Closed mgk closed 8 years ago
Thanks for raising the issue and apologies it took so long to be looked at. Great point about the exception causing trouble--I think my original intent was to only explode like this with an exception if something truly catastrophic happened and a retry couldn't work, but it looks like it causes more harm than good. I just changed it to instead log (to a debug level) the RC and move on to call the on disconnect handler. That way client code can at least check they're not connected and try to go on to connect again. Thanks again for raising the issue!
:+1: Yeah on reading the code it felt right to me too (as per your original intent). It was not until the disconnects happened that I started thinking about it the other way.
I have a publisher only application on an RPi2 that is event based and sends messages infrequently. It sometimes gets disconnected (possibly after inactivity as suggested here although my client runs for hours possibly days before I see the disconnect).
Whatever the cause of the disconnect clients should be able to reconnect, but adding an
on_disconnect()
callback does not work when there is a connection error as the Adafruit IO library throws aRuntimeError
as shown below. Further, this error cannot be caught as it happens in the background thread managing the MQTT communication.The net effect is that a disconnect when using
loop_background()
crashes the client.