Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace OSError exceptions from can_read with redis.ConnectionError #2140

Merged
merged 3 commits into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Small nit to remove a space.

                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}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

                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