From f555a484f90ab15266815af01717eb7818162361 Mon Sep 17 00:00:00 2001 From: James Lu Date: Wed, 15 Jun 2016 10:55:47 -0700 Subject: [PATCH] Irc: unconditionally call disconnect() on errors or ping timeouts This prevents duplicated ping timer threads from spawning, I think... --- classes.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/classes.py b/classes.py index 1c117c7..2aea6a1 100644 --- a/classes.py +++ b/classes.py @@ -277,10 +277,7 @@ class Irc(): log.error('(%s) Disconnected from IRC: %s: %s', self.name, type(e).__name__, str(e)) - if not self.aborted.is_set(): - # Only start a disconnection process if one doesn't already - # exist. - self.disconnect() + self.disconnect() # Internal hook signifying that a network has disconnected. self.callHooks([None, 'PYLINK_DISCONNECT', {}]) @@ -299,21 +296,15 @@ class Irc(): def disconnect(self): """Handle disconnects from the remote server.""" - log.debug('(%s) _disconnect: Clearing self.connected state.', self.name) + log.debug('(%s) disconnect: Clearing self.connected state.', self.name) self.connected.clear() - log.debug('(%s) _disconnect: Setting self.aborted to True.', self.name) - self.aborted.set() - - log.debug('(%s) disconnect: Clearing state via initVars().', self.name) - self.initVars() - log.debug('(%s) Removing channel logging handlers due to disconnect.', self.name) while self.loghandlers: log.removeHandler(self.loghandlers.pop()) try: - log.debug('(%s) _disconnect: Shutting down socket.', self.name) + log.debug('(%s) disconnect: Shutting down socket.', self.name) self.socket.shutdown(socket.SHUT_RDWR) except: # Socket timed out during creation; ignore pass @@ -324,6 +315,12 @@ class Irc(): log.debug('(%s) Canceling pingTimer at %s due to disconnect() call', self.name, time.time()) self.pingTimer.cancel() + log.debug('(%s) disconnect: Setting self.aborted to True.', self.name) + self.aborted.set() + + log.debug('(%s) disconnect: Clearing state via initVars().', self.name) + self.initVars() + def run(self): """Main IRC loop which listens for messages.""" # Some magic below cause this to work, though anything that's