From 2ef7df01e74107371c8855d3a69b297f35436040 Mon Sep 17 00:00:00 2001 From: James Lu Date: Wed, 12 Jul 2017 22:50:16 -0700 Subject: [PATCH] IRCNetwork: don't try to close the socket if none was ever initialized --- classes.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/classes.py b/classes.py index 53c8702..7778295 100644 --- a/classes.py +++ b/classes.py @@ -1111,6 +1111,7 @@ class IRCNetwork(PyLinkNetworkCoreWithUtils): self.connection_thread = None self.queue = None self.pingTimer = None + self.socket = None def init_vars(self, *args, **kwargs): super().init_vars(*args, **kwargs) @@ -1304,13 +1305,14 @@ class IRCNetwork(PyLinkNetworkCoreWithUtils): """Handle disconnects from the remote server.""" self._pre_disconnect() - try: - log.debug('(%s) disconnect: Shutting down socket.', self.name) - self.socket.shutdown(socket.SHUT_RDWR) - except Exception as e: # Socket timed out during creation; ignore - log.debug('(%s) error on socket shutdown: %s: %s', self.name, type(e).__name__, e) + if self.socket is not None: + try: + log.debug('(%s) disconnect: Shutting down socket.', self.name) + self.socket.shutdown(socket.SHUT_RDWR) + except Exception as e: # Socket timed out during creation; ignore + log.debug('(%s) error on socket shutdown: %s: %s', self.name, type(e).__name__, e) - self.socket.close() + self.socket.close() # Stop the queue thread. if self.queue: