mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
[3.11] gh-88863: Clear ref cycles to resolve leak when asyncio.open_connection raises (GH-95739) (#99721)
Break reference cycles to resolve memory leak, by
removing local exception and future instances from the frame.
(cherry picked from commit 995f6170c7
)
Co-authored-by: Dong Uk, Kang <nailbrainz@gmail.com>
This commit is contained in:
parent
609273eb52
commit
24fad64cef
4 changed files with 36 additions and 12 deletions
|
@ -630,7 +630,11 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
|
|||
|
||||
fut = self.create_future()
|
||||
self._sock_connect(fut, sock, address)
|
||||
return await fut
|
||||
try:
|
||||
return await fut
|
||||
finally:
|
||||
# Needed to break cycles when an exception occurs.
|
||||
fut = None
|
||||
|
||||
def _sock_connect(self, fut, sock, address):
|
||||
fd = sock.fileno()
|
||||
|
@ -652,6 +656,8 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
|
|||
fut.set_exception(exc)
|
||||
else:
|
||||
fut.set_result(None)
|
||||
finally:
|
||||
fut = None
|
||||
|
||||
def _sock_write_done(self, fd, fut, handle=None):
|
||||
if handle is None or not handle.cancelled():
|
||||
|
@ -675,6 +681,8 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
|
|||
fut.set_exception(exc)
|
||||
else:
|
||||
fut.set_result(None)
|
||||
finally:
|
||||
fut = None
|
||||
|
||||
async def sock_accept(self, sock):
|
||||
"""Accept a connection.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue