diff --git a/redis/connection.py b/redis/connection.py index faea7683f7..382bcddf4b 100644 --- a/redis/connection.py +++ b/redis/connection.py @@ -778,20 +778,22 @@ def on_connect(self): def disconnect(self, *args): "Disconnects from the Redis server" self._parser.on_disconnect() - if self._sock is None: + + socket = self._sock + self._sock = None + if socket is None: return if os.getpid() == self.pid: try: - self._sock.shutdown(socket.SHUT_RDWR) + socket.shutdown(socket.SHUT_RDWR) except OSError: pass try: - self._sock.close() + socket.close() except OSError: pass - self._sock = None def _send_ping(self): """Send PING, expect PONG in return"""