mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
gh-124858: fix happy eyeballs refcyles (#124859)
This commit is contained in:
parent
6810928927
commit
c066bf5535
4 changed files with 32 additions and 6 deletions
|
@ -17,7 +17,6 @@ import collections
|
|||
import collections.abc
|
||||
import concurrent.futures
|
||||
import errno
|
||||
import functools
|
||||
import heapq
|
||||
import itertools
|
||||
import os
|
||||
|
@ -1140,11 +1139,18 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
except OSError:
|
||||
continue
|
||||
else: # using happy eyeballs
|
||||
sock, _, _ = await staggered.staggered_race(
|
||||
(functools.partial(self._connect_sock,
|
||||
exceptions, addrinfo, laddr_infos)
|
||||
for addrinfo in infos),
|
||||
happy_eyeballs_delay, loop=self)
|
||||
sock = (await staggered.staggered_race(
|
||||
(
|
||||
# can't use functools.partial as it keeps a reference
|
||||
# to exceptions
|
||||
lambda addrinfo=addrinfo: self._connect_sock(
|
||||
exceptions, addrinfo, laddr_infos
|
||||
)
|
||||
for addrinfo in infos
|
||||
),
|
||||
happy_eyeballs_delay,
|
||||
loop=self,
|
||||
))[0] # can't use sock, _, _ as it keeks a reference to exceptions
|
||||
|
||||
if sock is None:
|
||||
exceptions = [exc for sub in exceptions for exc in sub]
|
||||
|
|
|
@ -133,6 +133,7 @@ async def staggered_race(coro_fns, delay, *, loop=None):
|
|||
raise d.exception()
|
||||
return winner_result, winner_index, exceptions
|
||||
finally:
|
||||
del exceptions
|
||||
# Make sure no tasks are left running if we leave this function
|
||||
for t in running_tasks:
|
||||
t.cancel()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue