]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109534: fix reference leak when SSL handshake fails (#114074)
authorJamie Phan <jamie@ordinarylab.dev>
Thu, 1 Feb 2024 00:42:17 +0000 (07:42 +0700)
committerGitHub <noreply@github.com>
Thu, 1 Feb 2024 00:42:17 +0000 (16:42 -0800)
Lib/asyncio/selector_events.py
Lib/asyncio/sslproto.py
Misc/NEWS.d/next/Library/2024-01-15-18-42-44.gh-issue-109534.wYaLMZ.rst [new file with mode: 0644]

index dcd5e0aa345029a3bf745734c10b8baf5dea8f56..10fbdd76e93f79c079f155e8cc0a393b57b290e4 100644 (file)
@@ -235,6 +235,10 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
                 await waiter
             except BaseException:
                 transport.close()
+                # gh-109534: When an exception is raised by the SSLProtocol object the
+                # exception set in this future can keep the protocol object alive and
+                # cause a reference cycle.
+                waiter = None
                 raise
                 # It's now up to the protocol to handle the connection.
 
index 599e91ba0003d10a4880e67d9fba951a06e1f629..fa99d4533aa0a6aff67d2949df3a1445aca16e29 100644 (file)
@@ -579,6 +579,7 @@ class SSLProtocol(protocols.BufferedProtocol):
 
             peercert = sslobj.getpeercert()
         except Exception as exc:
+            handshake_exc = None
             self._set_state(SSLProtocolState.UNWRAPPED)
             if isinstance(exc, ssl.CertificateError):
                 msg = 'SSL handshake failed on verifying the certificate'
diff --git a/Misc/NEWS.d/next/Library/2024-01-15-18-42-44.gh-issue-109534.wYaLMZ.rst b/Misc/NEWS.d/next/Library/2024-01-15-18-42-44.gh-issue-109534.wYaLMZ.rst
new file mode 100644 (file)
index 0000000..fc9a765
--- /dev/null
@@ -0,0 +1,3 @@
+Fix a reference leak in
+:class:`asyncio.selector_events.BaseSelectorEventLoop` when SSL handshakes
+fail. Patch contributed by Jamie Phan.