diff options
-rw-r--r-- | redis/asyncio/connection.py | 8 | ||||
-rwxr-xr-x | redis/connection.py | 8 |
2 files changed, 14 insertions, 2 deletions
diff --git a/redis/asyncio/connection.py b/redis/asyncio/connection.py index f0e6d3d..91961ba 100644 --- a/redis/asyncio/connection.py +++ b/redis/asyncio/connection.py @@ -911,7 +911,13 @@ class Connection: """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""" diff --git a/redis/connection.py b/redis/connection.py index ecbd32f..e0dcfc6 100755 --- a/redis/connection.py +++ b/redis/connection.py @@ -808,7 +808,13 @@ class Connection: 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""" |