Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing AttributeError on some connection errors #1905

Merged
merged 2 commits into from Jan 26, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions redis/connection.py
Expand Up @@ -805,15 +805,20 @@ 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}"
f"Error while reading from {hosterr}" f" : {e.args}"
)
except BaseException:
self.disconnect()
Expand Down