shawnanastasio / python-matrix-bot-api

A Python API for making Matrix bots (https://matrix.org).
GNU General Public License v3.0
92 stars 34 forks source link

When homeserver restarts, bot disconnects completely #12

Open ser opened 6 years ago

ser commented 6 years ago

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

lordievader commented 6 years ago

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.

shawnanastasio commented 5 years ago

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.

lordievader commented 5 years ago

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.