Skip to content

Commit d5c3428

Browse files
authored
fix: add socket shutdown before close for proper termination
1 parent 6317ef5 commit d5c3428

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

redis/connection.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,10 @@ def _connect(self):
764764
except OSError as _:
765765
err = _
766766
if sock is not None:
767+
try:
768+
sock.shutdown(socket.SHUT_RDWR) # ensure a clean close
769+
except:
770+
pass
767771
sock.close()
768772

769773
if err is not None:
@@ -1179,6 +1183,11 @@ def _connect(self):
11791183
sock.connect(self.path)
11801184
except OSError:
11811185
# Prevent ResourceWarnings for unclosed sockets.
1186+
try:
1187+
sock.shutdown(socket.SHUT_RDWR) # ensure a clean close
1188+
except:
1189+
pass
1190+
11821191
sock.close()
11831192
raise
11841193
sock.settimeout(self.socket_timeout)

0 commit comments

Comments
 (0)