-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Version: master
branch, at d1b4191
Platform: Python 3.12 on Linux in CI
Description:
CI shows that the test suite opens SSL sockets but doesn't always close them, resulting in ResourceWarning
s (recent example).
This is happening in two locations. In one location, a socket is opened but is only closed if an OSError
is encountered...but a RedisError
will be overlooked without also closing the socket:
Lines 819 to 824 in d1b4191
sock = super()._connect() | |
try: | |
return self._wrap_socket_with_ssl(sock) | |
except OSError: | |
sock.close() | |
raise |
In the second location, redis-py preemptively opens a second socket before it performs some validations that can result in a RedisError
(specifically, the RedisError
that is overlooked in the location shown above above). Once the exception is raised, there's no way to access and close the socket (sslsock
in the code snippet below) that was opened:
Lines 857 to 865 in d1b4191
sslsock = context.wrap_socket(sock, server_hostname=self.host) | |
if self.ssl_validate_ocsp is True and CRYPTOGRAPHY_AVAILABLE is False: | |
raise RedisError("cryptography is not installed.") | |
if self.ssl_validate_ocsp_stapled and self.ssl_validate_ocsp: | |
raise RedisError( | |
"Either an OCSP staple or pure OCSP connection must be validated " | |
"- not both." | |
) |
These unclosed sockets eventually get called out as ResourceWarning
s as the test suite exits.