From 4b55305b2f4d20e6ca4356bce3708c07284ffad0 Mon Sep 17 00:00:00 2001 From: Fran Garcia Date: Sun, 2 May 2021 22:07:29 +0100 Subject: [PATCH] Do not attempt to disconnect if connection is none When handling a ConnectionError we could be faced with the situation that we still don't have a connection, so attempting to disconnect would result in an error. To prevent this, we first check if the connection is None before attempting to disconnect. --- rediscluster/client.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rediscluster/client.py b/rediscluster/client.py index 58e6d1a6..a4d80f5e 100644 --- a/rediscluster/client.py +++ b/rediscluster/client.py @@ -647,7 +647,11 @@ def _execute_command(self, *args, **kwargs): except ConnectionError: log.exception("ConnectionError") - connection.disconnect() + # ConnectionError can also be raised if we couldn't get a connection + # from the pool before timing out, so check that this is an actual + # connection before attempting to disconnect. + if connection is not None: + connection.disconnect() connection_error_retry_counter += 1 # Give the node 0.1 seconds to get back up and retry again with same