Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,10 @@ def _connect(self):
except OSError as _:
err = _
if sock is not None:
try:
sock.shutdown(socket.SHUT_RDWR) # ensure a clean close
except OSError:
pass
sock.close()

if err is not None:
Expand Down Expand Up @@ -1179,6 +1183,10 @@ def _connect(self):
sock.connect(self.path)
except OSError:
# Prevent ResourceWarnings for unclosed sockets.
try:
sock.shutdown(socket.SHUT_RDWR) # ensure a clean close
except OSError:
pass
sock.close()
raise
sock.settimeout(self.socket_timeout)
Expand Down
Loading