Skip to content

Commit decec9a

Browse files
donbowmanpetyaslavova
authored andcommitted
fix: add TimeoutError handling in get_connection() (redis#1485)
* 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. * 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. * fix: update version number to match test expectations * fix: revert version number to 5.2.1, manually uninstall entraid
1 parent 540c3e8 commit decec9a

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

redis/asyncio/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ async def ensure_connection(self, connection: AbstractConnection):
11571157
try:
11581158
if await connection.can_read_destructive():
11591159
raise ConnectionError("Connection has data") from None
1160-
except (ConnectionError, OSError):
1160+
except (ConnectionError, TimeoutError, OSError):
11611161
await connection.disconnect()
11621162
await connection.connect()
11631163
if await connection.can_read_destructive():

redis/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ def get_connection(self, command_name=None, *keys, **options) -> "Connection":
14941494
try:
14951495
if connection.can_read() and self.cache is None:
14961496
raise ConnectionError("Connection has data")
1497-
except (ConnectionError, OSError):
1497+
except (ConnectionError, TimeoutError, OSError):
14981498
connection.disconnect()
14991499
connection.connect()
15001500
if connection.can_read():
@@ -1741,7 +1741,7 @@ def get_connection(self, command_name=None, *keys, **options):
17411741
try:
17421742
if connection.can_read():
17431743
raise ConnectionError("Connection has data")
1744-
except (ConnectionError, OSError):
1744+
except (ConnectionError, TimeoutError, OSError):
17451745
connection.disconnect()
17461746
connection.connect()
17471747
if connection.can_read():

0 commit comments

Comments
 (0)