Skip to content

Commit b5d5c30

Browse files
committed
Replace OSError exceptions from can_read with redis.ConnectionError
1 parent 6ba4641 commit b5d5c30

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

redis/asyncio/connection.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,13 @@ async def can_read(self, timeout: float = 0):
911911
"""Poll the socket to see if there's data that can be read."""
912912
if not self.is_connected:
913913
await self.connect()
914-
return await self._parser.can_read(timeout)
914+
try:
915+
return await self._parser.can_read(timeout)
916+
except OSError as e:
917+
await self.disconnect()
918+
raise ConnectionError(
919+
f"Error while reading from {self.host}:{self.port} : {e.args}"
920+
)
915921

916922
async def read_response(self, disable_decoding: bool = False):
917923
"""Read the response from a previously sent command"""

redis/connection.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,11 @@ def can_read(self, timeout=0):
808808
sock = self._sock
809809
if not sock:
810810
self.connect()
811-
return self._parser.can_read(timeout)
811+
try:
812+
return self._parser.can_read(timeout)
813+
except OSError as e:
814+
self.disconnect()
815+
raise ConnectionError(f"Error while reading from {self.host}:{self.port} : {e.args}")
812816

813817
def read_response(self, disable_decoding=False):
814818
"""Read the response from a previously sent command"""
@@ -1282,7 +1286,7 @@ class initializer. In the case of conflicting arguments, querystring
12821286
def __init__(
12831287
self, connection_class=Connection, max_connections=None, **connection_kwargs
12841288
):
1285-
max_connections = max_connections or 2 ** 31
1289+
max_connections = max_connections or 2**31
12861290
if not isinstance(max_connections, int) or max_connections < 0:
12871291
raise ValueError('"max_connections" must be a positive integer')
12881292

0 commit comments

Comments
 (0)