From 36515061dc893685b628c7de67891bc6fcee180d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 8 May 2023 17:45:21 +0000 Subject: [PATCH 1/4] Increase timeout for a test which would hang completely if failing. Timeouts in virtualized CI backends can occasionally fail if too short. --- tests/test_asyncio/test_commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_asyncio/test_commands.py b/tests/test_asyncio/test_commands.py index 955b9d42bc..5cde286a9e 100644 --- a/tests/test_asyncio/test_commands.py +++ b/tests/test_asyncio/test_commands.py @@ -3051,7 +3051,7 @@ async def helper(): # the task is now sleeping, lets send it an exception task.cancel() # If all is well, the task should finish right away, otherwise fail with Timeout - async with async_timeout(0.1): + async with async_timeout(1.0): await task From 4598d805d21251334e055103a88bd468ce907fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 8 May 2023 18:15:48 +0000 Subject: [PATCH 2/4] add "disconnect_on_error" argument to SentinelManagedConnection --- redis/asyncio/sentinel.py | 3 +++ redis/sentinel.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/redis/asyncio/sentinel.py b/redis/asyncio/sentinel.py index 9147ed83d1..501e234c3c 100644 --- a/redis/asyncio/sentinel.py +++ b/redis/asyncio/sentinel.py @@ -67,11 +67,14 @@ async def read_response( self, disable_decoding: bool = False, timeout: Optional[float] = None, + *, + disconnect_on_error: Optional[float] = True, ): try: return await super().read_response( disable_decoding=disable_decoding, timeout=timeout, + disconnect_on_error=disconnect_on_error, ) except ReadOnlyError: if self.connection_pool.is_master: diff --git a/redis/sentinel.py b/redis/sentinel.py index ac6921aa01..10f5f0dc14 100644 --- a/redis/sentinel.py +++ b/redis/sentinel.py @@ -6,6 +6,7 @@ from redis.connection import Connection, ConnectionPool, SSLConnection from redis.exceptions import ConnectionError, ReadOnlyError, ResponseError, TimeoutError from redis.utils import str_if_bytes +from typing import Optional class MasterNotFoundError(ConnectionError): @@ -53,9 +54,14 @@ def _connect_retry(self): def connect(self): return self.retry.call_with_retry(self._connect_retry, lambda error: None) - def read_response(self, disable_decoding=False): + def read_response( + self, disable_decoding=False, *, disconnect_on_error: Optional[bool] = False + ): try: - return super().read_response(disable_decoding=disable_decoding) + return super().read_response( + disable_decoding=disable_decoding, + disconnect_on_error=disconnect_on_error, + ) except ReadOnlyError: if self.connection_pool.is_master: # When talking to a master, a ReadOnlyError when likely From 1cc5b9230a41feb854fa5d35ccc68a126d45c2dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 8 May 2023 18:38:16 +0000 Subject: [PATCH 3/4] update Changes --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index 4917980126..1e03453cc3 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,4 @@ + * Fix #2754, adding a missing argument to SentinelManagedConnection * Fix `xadd` command to accept non-negative `maxlen` including 0 * Revert #2104, #2673, add `disconnect_on_error` option to `read_response()` (issues #2506, #2624) * Add `address_remap` parameter to `RedisCluster` From 8601474be88d115c4617398cb2a462b4a45eab17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 8 May 2023 18:51:34 +0000 Subject: [PATCH 4/4] lint --- redis/sentinel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis/sentinel.py b/redis/sentinel.py index 10f5f0dc14..f9f8f1c3ce 100644 --- a/redis/sentinel.py +++ b/redis/sentinel.py @@ -1,12 +1,12 @@ import random import weakref +from typing import Optional from redis.client import Redis from redis.commands import SentinelCommands from redis.connection import Connection, ConnectionPool, SSLConnection from redis.exceptions import ConnectionError, ReadOnlyError, ResponseError, TimeoutError from redis.utils import str_if_bytes -from typing import Optional class MasterNotFoundError(ConnectionError):