From ca53162f174267eb9ec0d50d89c1727994f32e52 Mon Sep 17 00:00:00 2001 From: Fran Garcia Date: Mon, 19 Jul 2021 12:43:02 +0100 Subject: [PATCH] Do not attempt to disconnect if there's no connection This is another case of https://github.com/Grokzen/redis-py-cluster/issues/453 There are cases in which we can get a `BaseException` before we have established a connection, which means that attempting to disconnect from it will result in an unhandled exception. --- rediscluster/client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rediscluster/client.py b/rediscluster/client.py index 844cb4c9..213953a3 100644 --- a/rediscluster/client.py +++ b/rediscluster/client.py @@ -710,7 +710,8 @@ def _execute_command(self, *args, **kwargs): redirect_addr, asking = "{0}:{1}".format(e.host, e.port), True except BaseException as e: log.exception("BaseException") - connection.disconnect() + if connection is not None: + connection.disconnect() raise e finally: if connection is not None: