-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Description
Version: master
branch, at d1b4191
Platform: Python 3.12 on Linux in CI
Description:
CI shows that there is an unclosed Unix socket when the test suite exits, which manifests as a ResourceWarning
(recent example).
This is happening because redis-py isn't closing the Unix socket when the call to sock.connect()
fails:
Lines 919 to 925 in d1b4191
def _connect(self): | |
"Create a Unix domain socket connection" | |
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
sock.settimeout(self.socket_connect_timeout) | |
sock.connect(self.path) | |
sock.settimeout(self.socket_timeout) | |
return sock |
The socket instance needs to be closed immediately if the call to sock.connect()
fails, while the object can still be referenced.
You can recreate this situation with this trivial reproducer:
$ python -Walways -c 'import socket; socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)'
<string>:1: ResourceWarning: unclosed <socket.socket fd=3, family=1, type=1, proto=0>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
Metadata
Metadata
Assignees
Labels
No labels