From 59ab61fc2f5245ffa92c1485af84fe37f23c1152 Mon Sep 17 00:00:00 2001 From: Don Bowman Date: Thu, 20 May 2021 18:00:12 -0400 Subject: [PATCH 1/4] fix: add TimeoutError handling in get_connection() In get_connection() we can implicitly call read on a connection. This can timeout of the underlying TCP session is gone. With this change we remove it from the connection pool and get a new connection. --- redis/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis/connection.py b/redis/connection.py index e3c9b66287..cf8c755a7f 100755 --- a/redis/connection.py +++ b/redis/connection.py @@ -1384,7 +1384,7 @@ def get_connection(self, command_name, *keys, **options): try: if connection.can_read(): raise ConnectionError('Connection has data') - except ConnectionError: + except (ConnectionError, TimeoutError): connection.disconnect() connection.connect() if connection.can_read(): From 05c12e0d3c375e98b8c0a3b05637da9089daec68 Mon Sep 17 00:00:00 2001 From: Don Bowman Date: Mon, 17 Mar 2025 21:19:00 -0400 Subject: [PATCH 2/4] fix: add TimeoutError handling in get_connection() sync/async In get_connection() we can implicitly call read on a connection. This can timeout of the underlying TCP session is gone. With this change we remove it from the connection pool and get a new connection. --- redis/asyncio/connection.py | 2 +- redis/connection.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/redis/asyncio/connection.py b/redis/asyncio/connection.py index 9b5d0d8eb9..ca52f58c83 100644 --- a/redis/asyncio/connection.py +++ b/redis/asyncio/connection.py @@ -1142,7 +1142,7 @@ async def ensure_connection(self, connection: AbstractConnection): try: if await connection.can_read_destructive(): raise ConnectionError("Connection has data") from None - except (ConnectionError, OSError): + except (ConnectionError, TimeoutError, OSError): await connection.disconnect() await connection.connect() if await connection.can_read_destructive(): diff --git a/redis/connection.py b/redis/connection.py index 83d378e9d2..f754a5165a 100644 --- a/redis/connection.py +++ b/redis/connection.py @@ -1,7 +1,6 @@ import copy import os import socket -import ssl import sys import threading import time @@ -49,6 +48,11 @@ str_if_bytes, ) +if SSL_AVAILABLE: + import ssl +else: + ssl = None + if HIREDIS_AVAILABLE: import hiredis @@ -1490,7 +1494,7 @@ def get_connection(self, command_name=None, *keys, **options) -> "Connection": try: if connection.can_read() and self.cache is None: raise ConnectionError("Connection has data") - except (ConnectionError, OSError): + except (ConnectionError, TimeoutError, OSError): connection.disconnect() connection.connect() if connection.can_read(): @@ -1736,7 +1740,7 @@ def get_connection(self, command_name=None, *keys, **options): # closed. either way, reconnect and verify everything is good. try: if connection.can_read(): - raise ConnectionError('Connection has data') + raise ConnectionError("Connection has data") except (ConnectionError, TimeoutError, OSError): connection.disconnect() connection.connect() From 302e89eaef20e7b6dfbdd0b0e30afd8b928498d7 Mon Sep 17 00:00:00 2001 From: Don Bowman Date: Mon, 17 Mar 2025 21:19:36 -0400 Subject: [PATCH 3/4] fix: update version number to match test expectations --- redis/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis/__init__.py b/redis/__init__.py index f82a876b2d..e170ce56b5 100644 --- a/redis/__init__.py +++ b/redis/__init__.py @@ -42,7 +42,7 @@ def int_or_str(value): return value -__version__ = "5.2.1" +__version__ = "5.3.0b3" VERSION = tuple(map(int_or_str, __version__.split("."))) From 42d0da9f88c9689a988bc970ddb718210857667c Mon Sep 17 00:00:00 2001 From: Don Bowman Date: Tue, 18 Mar 2025 08:29:37 -0400 Subject: [PATCH 4/4] fix: revert version number to 5.2.1, manually uninstall entraid --- redis/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis/__init__.py b/redis/__init__.py index e170ce56b5..f82a876b2d 100644 --- a/redis/__init__.py +++ b/redis/__init__.py @@ -42,7 +42,7 @@ def int_or_str(value): return value -__version__ = "5.3.0b3" +__version__ = "5.2.1" VERSION = tuple(map(int_or_str, __version__.split(".")))