summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-02-01 00:59:17 (GMT)
committerGitHub <noreply@github.com>2024-02-01 00:59:17 (GMT)
commitef2ba9a00757cc7bcf8f7b27afd0e9a634967f7c (patch)
tree579383e9d4277a376c6a09cb244758b0f48d68ef
parentfe0f544f33adf6128400f103187ba9f3cee13549 (diff)
downloadcpython-ef2ba9a00757cc7bcf8f7b27afd0e9a634967f7c.zip
cpython-ef2ba9a00757cc7bcf8f7b27afd0e9a634967f7c.tar.gz
cpython-ef2ba9a00757cc7bcf8f7b27afd0e9a634967f7c.tar.bz2
[3.11] gh-109534: fix reference leak when SSL handshake fails (GH-114074) (#114830)
gh-109534: fix reference leak when SSL handshake fails (GH-114074) (cherry picked from commit 80aa7b3688b8fdc85cd53d4113cb5f6ce5500027) Co-authored-by: Jamie Phan <jamie@ordinarylab.dev>
-rw-r--r--Lib/asyncio/selector_events.py4
-rw-r--r--Lib/asyncio/sslproto.py1
-rw-r--r--Misc/NEWS.d/next/Library/2024-01-15-18-42-44.gh-issue-109534.wYaLMZ.rst3
3 files changed, 8 insertions, 0 deletions
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
index 96e61f7..40df1b7d 100644
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -222,6 +222,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.
diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py
index 4d2cf82..e51669a 100644
--- a/Lib/asyncio/sslproto.py
+++ b/Lib/asyncio/sslproto.py
@@ -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
index 0000000..fc9a765
--- /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.