Skip to content

gh-135836: Fix IndexError in asyncio.create_connection with empty exceptions list #135845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ async def create_connection(
raise ExceptionGroup("create_connection failed", exceptions)
if len(exceptions) == 1:
raise exceptions[0]
else:
elif len(exceptions) > 1:
# If they all have the same str(), raise one.
model = str(exceptions[0])
if all(str(exc) == model for exc in exceptions):
Expand All @@ -1170,6 +1170,9 @@ async def create_connection(
# the various error messages.
raise OSError('Multiple exceptions: {}'.format(
', '.join(str(exc) for exc in exceptions)))
else:
# No exceptions were collected, raise a timeout error
raise TimeoutError('create_connection failed')
finally:
exceptions = None

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed :exc:`IndexError` in ``asyncio.create_connection()`` that could occur when the Happy Eyeballs algorithm resulted in an empty exceptions list during connection attempts.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Active voice and use a Sphinx ref:

Suggested change
Fixed :exc:`IndexError` in ``asyncio.create_connection()`` that could occur when the Happy Eyeballs algorithm resulted in an empty exceptions list during connection attempts.
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.

Loading