Skip to content

Commit

Permalink
[3.12] gh-109534: fix reference leak when SSL handshake fails (GH-114074
Browse files Browse the repository at this point in the history
) (#114829)

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

Co-authored-by: Jamie Phan <[email protected]>
  • Loading branch information
miss-islington and ordinary-jamie authored Feb 1, 2024
1 parent 21b68a1 commit 0ee6fba
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Lib/asyncio/selector_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions Lib/asyncio/sslproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a reference leak in
:class:`asyncio.selector_events.BaseSelectorEventLoop` when SSL handshakes
fail. Patch contributed by Jamie Phan.

0 comments on commit 0ee6fba

Please sign in to comment.