diff --git a/CHANGES b/CHANGES index b16fbce464..29af2c8ff5 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,4 @@ + * Close Connection on all send_command() errors (#2516) * Documentation fix: password protected socket connection (#2374) * Allow `timeout=None` in `PubSub.get_message()` to wait forever * add `nowait` flag to `asyncio.Connection.disconnect()` diff --git a/redis/asyncio/connection.py b/redis/asyncio/connection.py index 4f19153318..168ee4d7de 100644 --- a/redis/asyncio/connection.py +++ b/redis/asyncio/connection.py @@ -763,7 +763,11 @@ async def send_packed_command( raise ConnectionError( f"Error {err_no} while writing to socket. {errmsg}." ) from e - except Exception: + except BaseException: + # The send_packed_command api does not support re-trying a partially + # sent message, so there is no point in keeping the connection open. + # An unknown number of bytes has been sent and the connection is therefore + # unusable. await self.disconnect(nowait=True) raise diff --git a/redis/connection.py b/redis/connection.py index dce0735450..4ace49cb25 100755 --- a/redis/connection.py +++ b/redis/connection.py @@ -778,7 +778,11 @@ def send_packed_command(self, command, check_health=True): errno = e.args[0] errmsg = e.args[1] raise ConnectionError(f"Error {errno} while writing to socket. {errmsg}.") - except Exception: + except BaseException: + # The send_packed_command api does not support re-trying a partially + # sent message, so there is no point in keeping the connection open. + # An unknown number of bytes has been sent and the connection is therefore + # unusable. self.disconnect() raise