summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/windows_events.py
diff options
context:
space:
mode:
authorDong Uk, Kang <nailbrainz@gmail.com>2022-11-22 15:06:20 (GMT)
committerGitHub <noreply@github.com>2022-11-22 15:06:20 (GMT)
commit995f6170c78570eca818f7e7dbd8a7661c171a81 (patch)
treefdfaf448f9fb3bf4a601c1cb51c001deab62ea01 /Lib/asyncio/windows_events.py
parent9a91182d4a87e4511dad20ad101e3eab0e1c5088 (diff)
downloadcpython-995f6170c78570eca818f7e7dbd8a7661c171a81.zip
cpython-995f6170c78570eca818f7e7dbd8a7661c171a81.tar.gz
cpython-995f6170c78570eca818f7e7dbd8a7661c171a81.tar.bz2
gh-88863: Clear ref cycles to resolve leak when asyncio.open_connection raises (#95739)
Break reference cycles to resolve memory leak, by removing local exception and future instances from the frame
Diffstat (limited to 'Lib/asyncio/windows_events.py')
-rw-r--r--Lib/asyncio/windows_events.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/asyncio/windows_events.py b/Lib/asyncio/windows_events.py
index acc97da..4dad436 100644
--- a/Lib/asyncio/windows_events.py
+++ b/Lib/asyncio/windows_events.py
@@ -439,7 +439,11 @@ class IocpProactor:
self._poll(timeout)
tmp = self._results
self._results = []
- return tmp
+ try:
+ return tmp
+ finally:
+ # Needed to break cycles when an exception occurs.
+ tmp = None
def _result(self, value):
fut = self._loop.create_future()
@@ -793,6 +797,8 @@ class IocpProactor:
else:
f.set_result(value)
self._results.append(f)
+ finally:
+ f = None
# Remove unregistered futures
for ov in self._unregistered: