From 9fe836698ca5930e39633b86839b6c1bae07237e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Thu, 29 Sep 2022 11:03:54 +0000 Subject: Catch `Exception` and not `BaseException` in the `Connection` (#2104) * Add failing unittests for passing BaseException through * Resolve failing unittest * Remove redundant checks for asyncio.CancelledError --- redis/asyncio/connection.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'redis/asyncio/connection.py') diff --git a/redis/asyncio/connection.py b/redis/asyncio/connection.py index 16f33e2..a470b6f 100644 --- a/redis/asyncio/connection.py +++ b/redis/asyncio/connection.py @@ -502,8 +502,6 @@ class HiredisParser(BaseParser): # data was read from the socket and added to the buffer. # return True to indicate that data was read. return True - except asyncio.CancelledError: - raise except (socket.timeout, asyncio.TimeoutError): if raise_on_timeout: raise TimeoutError("Timeout reading from socket") from None @@ -721,7 +719,7 @@ class Connection: lambda: self._connect(), lambda error: self.disconnect() ) except asyncio.CancelledError: - raise + raise # in 3.7 and earlier, this is an Exception, not BaseException except (socket.timeout, asyncio.TimeoutError): raise TimeoutError("Timeout connecting to server") except OSError as e: @@ -916,7 +914,7 @@ class Connection: raise ConnectionError( f"Error {err_no} while writing to socket. {errmsg}." ) from e - except BaseException: + except Exception: await self.disconnect() raise @@ -958,7 +956,7 @@ class Connection: raise ConnectionError( f"Error while reading from {self.host}:{self.port} : {e.args}" ) - except BaseException: + except Exception: await self.disconnect() raise -- cgit v1.2.1