From 6dd8f88bf659ed0648d944104a121dff2d544749 Mon Sep 17 00:00:00 2001 From: "Vgr E. Barry" Date: Thu, 8 Oct 2015 12:03:08 -0400 Subject: [PATCH] Ensure socket is closed unconditionally (re: #169) I cannot reproduce the bug locally, but this will force the socket to close if it didn't for whatever reason, which is what seems like could have caused the issue. --- src/wolfgame.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/wolfgame.py b/src/wolfgame.py index d7a56a6..ba33762 100644 --- a/src/wolfgame.py +++ b/src/wolfgame.py @@ -531,6 +531,8 @@ def forced_exit(cli, nick, chan, rest): except Exception: traceback.print_exc() sys.exit() + finally: + cli.socket.close() # in case it didn't close, force it to def _restart_program(cli, mode=None): @@ -616,8 +618,11 @@ def restart_program(cli, nick, chan, rest): nick, _, __, host = parse_nick(raw_nick) # restart the bot once our quit message goes though to ensure entire IRC queue is sent # if the bot is using a nick that isn't botconfig.NICK, then stop breaking things and fdie - if nick == botconfig.NICK: - _restart_program(cli, mode) + try: + if nick == botconfig.NICK: + _restart_program(cli, mode) + finally: + cli.socket.close() # This is checked in the on_error handler. Some IRCds, such as InspIRCd, don't send the bot # its own QUIT message, so we need to use ERROR. Ideally, we shouldn't even need the above