Skip to content

Commit 80aa7b3

Browse files
gh-109534: fix reference leak when SSL handshake fails (#114074)
1 parent 7b9d406 commit 80aa7b3

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
@@ -235,6 +235,10 @@ async def _accept_connection2(
235235
await waiter
236236
except BaseException:
237237
transport.close()
238+
# gh-109534: When an exception is raised by the SSLProtocol object the
239+
# exception set in this future can keep the protocol object alive and
240+
# cause a reference cycle.
241+
waiter = None
238242
raise
239243
# It's now up to the protocol to handle the connection.
240244

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)