From 3e6a19828bcd6249fb827e19b9611f9c5ecb9ecb Mon Sep 17 00:00:00 2001 From: Humorous Baby Date: Fri, 29 Mar 2019 22:47:10 -0400 Subject: [PATCH 1/2] fix: interrupt during connection phase Adds a check to the `bot.quit` method to ensure that a socket exists before writing the `QUIT` message. This prevents the unhandled `AttributeError` that prevents a clean quit when the connection phase is interrupted --- sopel/irc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sopel/irc.py b/sopel/irc.py index aa0597bcae..1e104367cc 100644 --- a/sopel/irc.py +++ b/sopel/irc.py @@ -189,7 +189,8 @@ def initiate_connect(self, host, port): def quit(self, message): """Disconnect from IRC and close the bot.""" - self.write(['QUIT'], message) + if self.connected: # Only send QUIT message if socket is open + self.write(['QUIT'], message) self.hasquit = True # Wait for acknowledgement from the server. By RFC 2812 it should be # an ERROR msg, but many servers just close the connection. Either way From 9dd772d91fd40f2e12c7dba57c45c01be58d66e3 Mon Sep 17 00:00:00 2001 From: Humorous Baby Date: Fri, 29 Mar 2019 22:55:00 -0400 Subject: [PATCH 2/2] fix: interrupt during disconnected phase Because the `time.sleep` during the disconnect phase, the signal handling is thrown off and a new bot is spawned before the `bot.hasquit` flag can be checked. Add a check at the top of the loop to see if the `hasquit` flag was set during a disconnect. Fixes #1478 --- sopel/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sopel/__init__.py b/sopel/__init__.py index a0cbdaf6ee..b99681d3db 100644 --- a/sopel/__init__.py +++ b/sopel/__init__.py @@ -71,7 +71,12 @@ def signal_handler(sig, frame): if sig == signal.SIGUSR1 or sig == signal.SIGTERM or sig == signal.SIGINT: stderr('Got quit signal, shutting down.') p.quit('Closing') + + # Define empty variable `p` for bot + p = None while True: + if p and p.hasquit: # Check if `hasquit` was set for bot during disconnected phase + break try: p = bot.Sopel(config, daemon=daemon) if hasattr(signal, 'SIGUSR1'):