python-matrix-bot-api
python-matrix-bot-api copied to clipboard
When homeserver restarts, bot disconnects completely
When homeserver restarts, bot disconnects with exception
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))
and does not try to reconnect again, which is extremely annoying as requires restart of the bot
This also happens when the bot looses connection with the homeserver. It leaves the bot in some kind of a zombie state. I have my bot in a systemd service and it doesn't get restarted since systemd thinks it is still running fine.
I can't see anywhere where I'm ignoring exceptions, so the issue must be in matrix-python-sdk
. I'll do some more digging to see if there's a way to get the error to propagate properly.
I must say with the latest version, were you get a reference to the thread the bot is in, the main program does notice the thread dying in the event of a connection abort.
Perhaps lines 75 through 80 of "example_bot.py" should be replaced with:
# Start polling
while True:
thread = bot.start_polling()
thread.join()
logging.warning(
'thread died, waiting five seconds before connecting again...')
time.sleep(5)
This piece of code assumes the thread died because of a connection error. However, this might not always be the case. I've implemented it this way because I don't know how to pull the actual exception from the thread reference.