Skip to content

Commit 7affd38

Browse files
committed
fix: workaround asyncio bug on connection reset by peer
Fixes redis#2237
1 parent e6cd4fd commit 7affd38

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

redis/asyncio/connection.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,16 @@ async def _connect(self):
767767
def _error_message(self, exception):
768768
# args for socket.error can either be (errno, "message")
769769
# or just "message"
770-
if len(exception.args) == 1:
770+
if not exception.args:
771+
# asyncio has a bug where on Connection reset by peer, the
772+
# exception is not instanciated, so args is empty. This is the
773+
# workaround.
774+
# See: https://github.com/redis/redis-py/issues/2237
775+
# See: https://github.com/python/cpython/issues/94061
776+
return (
777+
f"Error connecting to {self.host}:{self.port}. Connection reset by peer"
778+
)
779+
elif len(exception.args) == 1:
771780
return f"Error connecting to {self.host}:{self.port}. {exception.args[0]}."
772781
else:
773782
return (

0 commit comments

Comments
 (0)