https://github.com/python/cpython/commit/0ee6fbaab6888dc0252c497b13a7ba73f5172931
commit: 0ee6fbaab6888dc0252c497b13a7ba73f5172931
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: hauntsaninja <[email protected]>
date: 2024-02-01T01:00:09Z
summary:

[3.12] gh-109534: fix reference leak when SSL handshake fails (GH-114074) 
(#114829)

gh-109534: fix reference leak when SSL handshake fails (GH-114074)
(cherry picked from commit 80aa7b3688b8fdc85cd53d4113cb5f6ce5500027)

Co-authored-by: Jamie Phan <[email protected]>

files:
A Misc/NEWS.d/next/Library/2024-01-15-18-42-44.gh-issue-109534.wYaLMZ.rst
M Lib/asyncio/selector_events.py
M Lib/asyncio/sslproto.py

diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
index f895750e3cf959..790711f834096b 100644
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -235,6 +235,10 @@ async def _accept_connection2(
                 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.
 
diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py
index 4d2cf8224ae4cf..e51669a2ab2af6 100644
--- a/Lib/asyncio/sslproto.py
+++ b/Lib/asyncio/sslproto.py
@@ -579,6 +579,7 @@ def _on_handshake_complete(self, handshake_exc):
 
             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
index 00000000000000..fc9a765a230037
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-01-15-18-42-44.gh-issue-109534.wYaLMZ.rst
@@ -0,0 +1,3 @@
+Fix a reference leak in
+:class:`asyncio.selector_events.BaseSelectorEventLoop` when SSL handshakes
+fail. Patch contributed by Jamie Phan.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to