diff --git a/Lib/ssl.py b/Lib/ssl.py index d01484964b6895..a72c190425652f 100644 --- a/Lib/ssl.py +++ b/Lib/ssl.py @@ -1017,6 +1017,7 @@ def _create(cls, sock, server_side=False, do_handshake_on_connect=True, self.getpeername() except OSError as e: if e.errno != errno.ENOTCONN: + self.close() raise connected = False blocking = self.getblocking() @@ -1030,6 +1031,7 @@ def _create(cls, sock, server_side=False, do_handshake_on_connect=True, except OSError as e: # EINVAL occurs for recv(1) on non-connected on unix sockets. if e.errno not in (errno.ENOTCONN, errno.EINVAL): + self.close() raise notconn_pre_handshake_data = b'' self.setblocking(blocking) diff --git a/Misc/NEWS.d/next/Library/2023-12-19-10-05-45.gh-issue-113280.qIia3M.rst b/Misc/NEWS.d/next/Library/2023-12-19-10-05-45.gh-issue-113280.qIia3M.rst new file mode 100644 index 00000000000000..f4c9510031ed96 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-12-19-10-05-45.gh-issue-113280.qIia3M.rst @@ -0,0 +1 @@ +Fix :class:`ResourceWarning` in :class:`ssl.SSLSocket` connected detection