Skip to content

Commit

Permalink
Close Unix sockets if the connection attempt fails
Browse files Browse the repository at this point in the history
Make sure Unix sockets get closed if the connection fails.

Co-authored-by: Salvatore Mesoraca <salvatore.mesoraca@aiven.io>
Signed-off-by: Salvatore Mesoraca <salvatore.mesoraca@aiven.io>
  • Loading branch information
kurtmckee and aiven-sal committed Aug 7, 2024
1 parent c8e78fb commit 1889058
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion valkey/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,12 @@ 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)
try:
sock.connect(self.path)
except OSError:
# Prevent ResourceWarnings for unclosed sockets.
sock.close()
raise
sock.settimeout(self.socket_timeout)
return sock

Expand Down

0 comments on commit 1889058

Please sign in to comment.