Skip to content

Commit 00f8d6b

Browse files
kurtmckeevladvildanov
authored andcommitted
Close Unix sockets if the connection attempt fails (#3315)
Make sure Unix sockets get closed if the connection fails. Fixes #3314
1 parent e94b6e5 commit 00f8d6b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
* Improve error output for master discovery
6464
* Make `ClusterCommandsProtocol` an actual Protocol
6565
* Add `sum` to DUPLICATE_POLICY documentation of `TS.CREATE`, `TS.ADD` and `TS.ALTER`
66+
* Prevent async ClusterPipeline instances from becoming "false-y" in case of empty command stack (#3061)
67+
* Close Unix sockets if the connection attempt fails. This prevents `ResourceWarning`s. (#3314)
6668

6769
* 4.1.3 (Feb 8, 2022)
6870
* Fix flushdb and flushall (#1926)

redis/connection.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,12 @@ def _connect(self):
920920
"Create a Unix domain socket connection"
921921
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
922922
sock.settimeout(self.socket_connect_timeout)
923-
sock.connect(self.path)
923+
try:
924+
sock.connect(self.path)
925+
except OSError:
926+
# Prevent ResourceWarnings for unclosed sockets.
927+
sock.close()
928+
raise
924929
sock.settimeout(self.socket_timeout)
925930
return sock
926931

0 commit comments

Comments
 (0)