python-matrix-bot-api icon indicating copy to clipboard operation
python-matrix-bot-api copied to clipboard

When homeserver restarts, bot disconnects completely

Open ser opened this issue 6 years ago • 3 comments

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

ser avatar Jun 04 '18 23:06 ser

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.

lordievader avatar Sep 06 '18 07:09 lordievader

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.

shawnanastasio avatar Jan 22 '19 04:01 shawnanastasio

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.

lordievader avatar Jan 22 '19 13:01 lordievader