From 7f4f114c12bccd4fadc45c39be699bc0754969d9 Mon Sep 17 00:00:00 2001 From: Tomas Van den Hauwe Date: Thu, 7 Nov 2024 14:54:37 -0800 Subject: [PATCH] Fix handling of unsupported client_list() command --- rq/worker.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/rq/worker.py b/rq/worker.py index 2122e58c..f2f23b6f 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -227,20 +227,20 @@ class BaseWorker: if prepare_for_work: self.hostname: Optional[str] = socket.gethostname() self.pid: Optional[int] = os.getpid() + self.ip_address = 'unknown' try: connection.client_setname(self.name) except redis.exceptions.ResponseError: warnings.warn('CLIENT SETNAME command not supported, setting ip_address to unknown', Warning) - self.ip_address = 'unknown' else: - client_adresses = [ - client['addr'] for client in connection.client_list() if client.get('name') == self.name - ] - if len(client_adresses) > 0: - self.ip_address = client_adresses[0] - else: + try: + client_adresses = [ + client['addr'] for client in connection.client_list() if client.get('name') == self.name + ] + if len(client_adresses) > 0: + self.ip_address = client_adresses[0] + except redis.exceptions.ResponseError: warnings.warn('CLIENT LIST command not supported, setting ip_address to unknown', Warning) - self.ip_address = 'unknown' else: self.hostname = None self.pid = None