8000 [3.11] gh-109534: fix reference leak when SSL handshake fails (GH-114… · python/cpython@ef2ba9a · GitHub
[go: up one dir, main page]

Skip to content

Commit ef2ba9a

Browse files
[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 80aa7b3) Co-authored-by: Jamie Phan <jamie@ordinarylab.dev>
1 parent fe0f544 commit ef2ba9a

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

Lib/asyncio/selector_events.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ async def _accept_connection2(
222222
await waiter
223223
except BaseException:
224224
transport.close()
225+
# gh-109534: When an exception is raised by the SSLProtocol object the
226+
# exception set in this future can keep the protocol object alive and
227+
# cause a reference cycle.
228+
waiter = None
225229
raise
226230
# It's now up to the protocol to handle the connection.
227231

Lib/asyncio/sslproto.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ def _on_handshake_complete(self, handshake_exc):
579579

580580
peercert = sslobj.getpeercert()
581581
except Exception as exc:
582+
handshake_exc = None
582583
self._set_state(SSLProtocolState.UNWRAPPED)
583584
if isinstance(exc, ssl.CertificateError):
584585
msg = 'SSL handshake failed on verifying the certificate'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a reference leak in
2+
:class:`asyncio.selector_events.BaseSelectorEventLoop` when SSL handshakes
3+
fail. Patch contributed by Jamie Phan.

0 commit comments

Comments
 (0)
0