Skip to content

Commit

Permalink
fix: workaround asyncio bug on connection reset by peer (#2259)
Browse files Browse the repository at this point in the history
Fixes #2237
  • Loading branch information
sileht authored and dvora-h committed Nov 21, 2022
1 parent cc07235 commit a4ff8a6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion redis/asyncio/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit a4ff8a6

Please sign in to comment.