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 all commits
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}"
)

async def read_response(self, disable_decoding: bool = False):
"""Read the response from a previously sent command"""
Expand Down
8 changes: 7 additions & 1 deletion redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,13 @@ 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