Skip to content

Commit

Permalink
Fixing AttributeError on some connection errors (redis#1905)
Browse files Browse the repository at this point in the history
  • Loading branch information
chayim authored and dvora-h committed Feb 2, 2022
1 parent 5222d6a commit dfd2263
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions redis/connection.py
Expand Up @@ -805,16 +805,19 @@ def can_read(self, timeout=0):

def read_response(self, disable_decoding=False):
"""Read the response from a previously sent command"""
try:
hosterr = f"{self.host}:{self.port}"
except AttributeError:
hosterr = "connection"

try:
response = self._parser.read_response(disable_decoding=disable_decoding)
except socket.timeout:
self.disconnect()
raise TimeoutError(f"Timeout reading from {self.host}:{self.port}")
raise TimeoutError(f"Timeout reading from {hosterr}")
except OSError as e:
self.disconnect()
raise ConnectionError(
f"Error while reading from {self.host}:{self.port}" f" : {e.args}"
)
raise ConnectionError(f"Error while reading from {hosterr}" f" : {e.args}")
except BaseException:
self.disconnect()
raise
Expand Down

0 comments on commit dfd2263

Please sign in to comment.