From 03c21d836993338894c91551d10d86dbd4541114 Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Fri, 19 Mar 2021 21:41:18 +0000 Subject: [PATCH] Explicitly clear joined channels when reconnecting If we try to reconnect after an error sending a message to the IRC server, clear the tracking of which channels are currently joined, since none will be joined once reconnected. This fixes a longstanding regression where the bot would appear to quit the network and never return, when in actuality it just didn't know it needed to rejoin channels once reconnected. Change-Id: Ic865e307609285708c40e11a66b4b9643afc178e --- gerritbot/bot.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gerritbot/bot.py b/gerritbot/bot.py index 3d797e9..6dcdcf0 100755 --- a/gerritbot/bot.py +++ b/gerritbot/bot.py @@ -131,7 +131,12 @@ class GerritBot(SASL, SSL, irc.bot.SingleServerIRCBot): self.connection.privmsg(channel_name, msg) time.sleep(0.5) except Exception: + # If an exception was raised on sending, suspect that there may be + # trouble with the connection and try to reconnect, explicitly + # clearing the set of channels joined so the bot will join them + # again afterward as needed self.log.exception('Exception sending message:') + self.joined_channels = {} self.connection.reconnect()