diff --git a/redis/asyncio/connection.py b/redis/asyncio/connection.py index cb18a5a2f0..7f9a0c7ee6 100644 --- a/redis/asyncio/connection.py +++ b/redis/asyncio/connection.py @@ -767,7 +767,16 @@ async def _connect(self): def _error_message(self, exception): # args for socket.error can either be (errno, "message") # or just "message" - if len(exception.args) == 1: + if not exception.args: + # asyncio has a bug where on Connection reset by peer, the + # exception is not instanciated, so args is empty. This is the + # workaround. + # See: https://github.com/redis/redis-py/issues/2237 + # See: https://github.com/python/cpython/issues/94061 + return ( + f"Error connecting to {self.host}:{self.port}. Connection reset by peer" + ) + elif len(exception.args) == 1: return f"Error connecting to {self.host}:{self.port}. {exception.args[0]}." else: return (