Skip to content

Commit

Permalink
Replace OSError exceptions from can_read with redis.ConnectionError
Browse files Browse the repository at this point in the history
  • Loading branch information
kristjanvalur committed Apr 25, 2022
1 parent 6ba4641 commit b5d5c30
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion redis/asyncio/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,13 @@ async def can_read(self, timeout: float = 0):
"""Poll the socket to see if there's data that can be read."""
if not self.is_connected:
await self.connect()
return await self._parser.can_read(timeout)
try:
return await self._parser.can_read(timeout)
except OSError as e:
await self.disconnect()
raise ConnectionError(
f"Error while reading from {self.host}:{self.port} : {e.args}"
)

async def read_response(self, disable_decoding: bool = False):
"""Read the response from a previously sent command"""
Expand Down
8 changes: 6 additions & 2 deletions redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,11 @@ def can_read(self, timeout=0):
sock = self._sock
if not sock:
self.connect()
return self._parser.can_read(timeout)
try:
return self._parser.can_read(timeout)
except OSError as e:
self.disconnect()
raise ConnectionError(f"Error while reading from {self.host}:{self.port} : {e.args}")

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

Expand Down

0 comments on commit b5d5c30

Please sign in to comment.