Skip to content

Commit d7e4ea1

Browse files
silehtdvora-h
authored andcommitted
fix: workaround asyncio bug on connection reset by peer (redis#2259)
Fixes redis#2237
1 parent 439f2ea commit d7e4ea1

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
@@ -771,7 +771,16 @@ async def _connect(self):
771771
def _error_message(self, exception):
772772
# args for socket.error can either be (errno, "message")
773773
# or just "message"
774-
if len(exception.args) == 1:
774+
if not exception.args:
775+
# asyncio has a bug where on Connection reset by peer, the
776+
# exception is not instanciated, so args is empty. This is the
777+
# workaround.
778+
# See: https://github.com/redis/redis-py/issues/2237
779+
# See: https://github.com/python/cpython/issues/94061
780+
return (
781+
f"Error connecting to {self.host}:{self.port}. Connection reset by peer"
782+
)
783+
elif len(exception.args) == 1:
775784
return f"Error connecting to {self.host}:{self.port}. {exception.args[0]}."
776785
else:
777786
return (

0 commit comments

Comments
 (0)