jheling / freeathome

Free@Home component for Home Assistant
103 stars 37 forks source link

Reconnect XMPP client after error #62

Closed Tho85 closed 3 years ago

Tho85 commented 3 years ago

In the past, whenever I restarted my SysAP the XMPP client threw an error and failed to reconnect afterwards. I had to restart home-assistant afterwards to recover. This was the error message:

2020-07-06 22:34:49 ERROR (MainThread) [slixmpp.xmlstream.xmlstream] Exception raised in send queue:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/slixmpp/xmlstream/xmlstream.py", line 1007, in run_filters
    self.send_raw(str_data)
  File "/usr/local/lib/python3.7/site-packages/slixmpp/xmlstream/xmlstream.py", line 1043, in send_raw
    raise NotConnectedError()
slixmpp.xmlstream.xmlstream.NotConnectedError

You can reproduce this on current master when you restart your SysAP or kill the TCP connection otherwise (e.g. tcpkill).

This PR adds logic to reconnect after the XMPP client disconnects, regardless of the reason. It is basically @miezie's work here, enhanced by reinitialising the SaslHandler needed since 2.3.0. I had this patch running for months in my local setup, and it worked flawlessly.

jheling commented 3 years ago

Thank you very much for sharing this