diff --git a/redis/asyncio/client.py b/redis/asyncio/client.py index 9e16ee08de..5de2ff960c 100644 --- a/redis/asyncio/client.py +++ b/redis/asyncio/client.py @@ -702,6 +702,11 @@ async def reset(self): self.pending_unsubscribe_patterns = set() def close(self) -> Awaitable[NoReturn]: + # In case a connection property does not yet exist + # (due to a crash earlier in the Redis() constructor), return + # immediately as there is nothing to clean-up. + if not hasattr(self, "connection"): + return return self.reset() async def on_connect(self, connection: Connection):