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

Conversation

heliang666s
Copy link

@heliang666s heliang666s commented Jun 23, 2025

Fix IndexError that occurs in asyncio.create_connection() when Happy Eyeballs algorithm leaves empty sublists in the exceptions list, which after flattening becomes an empty list causing str(exceptions[0]) to crash. The fix adds explicit handling for empty exceptions list by changing 'else:' to 'elif len(exceptions) > 1:' and adding a new else clause that raises OSError('create_connection failed') instead of crashing.

Fix IndexError that occurs in asyncio.create_connection() when Happy Eyeballs algorithm leaves empty sublists in the exceptions list, which after flattening becomes an empty list causing str(exceptions[0]) to crash. The fix adds explicit handling for empty exceptions list by changing 'else:' to 'elif len(exceptions) > 1:' and adding a new else clause that raises OSError('create_connection failed') instead of crashing.
@python-cla-bot
Copy link

python-cla-bot bot commented Jun 23, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Jun 23, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

blurb-it bot and others added 3 commits June 23, 2025 11:04
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

The approach LGTM, but please add a test. You can take test_create_connection_timeout as example. It only tests for happy_eyeballs_delay=None (default), we need a test for non-None value.

Core developer suggested TimeoutError is more appropriate when empty
exceptions list indicates all connections exceeded their timeout.
@@ -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.

@serhiy-storchaka
Copy link
Member

Please don't forget about test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants