Skip to content

Commit ab54b85

Browse files
committed
gh-135836: take into account staggered exceptions
1 parent 34393cb commit ab54b85

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Lib/asyncio/base_events.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,7 @@ async def create_connection(
11311131
infos = _interleave_addrinfos(infos, interleave)
11321132

11331133
exceptions = []
1134+
staggered_exceptions = []
11341135
if happy_eyeballs_delay is None:
11351136
# not using happy eyeballs
11361137
for addrinfo in infos:
@@ -1141,7 +1142,7 @@ async def create_connection(
11411142
except OSError:
11421143
continue
11431144
else: # using happy eyeballs
1144-
sock = (await staggered.staggered_race(
1145+
sock, _, staggered_exceptions = (await staggered.staggered_race(
11451146
(
11461147
# can't use functools.partial as it keeps a reference
11471148
# to exceptions
@@ -1152,10 +1153,15 @@ async def create_connection(
11521153
),
11531154
happy_eyeballs_delay,
11541155
loop=self,
1155-
))[0] # can't use sock, _, _ as it keeks a reference to exceptions
1156+
))
11561157

11571158
if sock is None:
11581159
exceptions = [exc for sub in exceptions for exc in sub]
1160+
for exc in staggered_exceptions:
1161+
if not (isinstance(exc, CancelledError) or exc in exceptions):
1162+
exceptions.append(exc)
1163+
del exc
1164+
11591165
try:
11601166
if all_errors:
11611167
raise ExceptionGroup("create_connection failed", exceptions)
@@ -1172,6 +1178,7 @@ async def create_connection(
11721178
', '.join(str(exc) for exc in exceptions)))
11731179
finally:
11741180
exceptions = None
1181+
staggered_exceptions = None
11751182

11761183
else:
11771184
if sock is None:

0 commit comments

Comments
 (0)