Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,7 @@ async def create_connection(
infos = _interleave_addrinfos(infos, interleave)

exceptions = []
staggered_exceptions = []
if happy_eyeballs_delay is None:
# not using happy eyeballs
for addrinfo in infos:
Expand All @@ -1141,7 +1142,7 @@ async def create_connection(
except OSError:
continue
else: # using happy eyeballs
sock = (await staggered.staggered_race(
sock, _, staggered_exceptions = (await staggered.staggered_race(
(
# can't use functools.partial as it keeps a reference
# to exceptions
Expand All @@ -1152,10 +1153,15 @@ async def create_connection(
),
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]
for exc in staggered_exceptions:
if not (isinstance(exc, CancelledError) or exc in exceptions):
exceptions.append(exc)
del exc

try:
if all_errors:
raise ExceptionGroup("create_connection failed", exceptions)
Expand All @@ -1172,6 +1178,7 @@ async def create_connection(
', '.join(str(exc) for exc in exceptions)))
finally:
exceptions = None
staggered_exceptions = None

else:
if sock is None:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :exc:`IndexError` in :meth:`asyncio.loop.create_connection` that could occur when the Happy Eyeballs algorithm resulted in an empty exceptions list during connection attempts, by capturing any exceptions raises by ``staggered_race``
Loading