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.
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'
--- /dev/null
+Fix a reference leak in
+:class:`asyncio.selector_events.BaseSelectorEventLoop` when SSL handshakes
+fail. Patch contributed by Jamie Phan.