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
This commit is contained in:
Jeremy Stanley 2021-03-19 21:41:18 +00:00
parent 225a6a3502
commit 03c21d8369
1 changed files with 5 additions and 0 deletions

View File

@ -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()