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

Conversation

heliang666s
Copy link
Contributor

@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.
@serhiy-storchaka
Copy link
Member

Please don't forget about test.

@heliang666s
Copy link
Contributor Author

I think this pr is ready for merge. cc @serhiy-storchaka @ZeroIntensity

…e synchronous and check correct error message
heliang666s and others added 2 commits July 1, 2025 19:19
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
@kumaraditya303 kumaraditya303 added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jul 1, 2025
@kumaraditya303 kumaraditya303 enabled auto-merge (squash) July 1, 2025 11:31
@kumaraditya303 kumaraditya303 merged commit 0e19db6 into python:main Jul 1, 2025
48 checks passed
@miss-islington-app
Copy link

Thanks @heliang666s for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 1, 2025
… empty exceptions list (pythonGH-135845)

(cherry picked from commit 0e19db6)

Co-authored-by: heliang666s <147408835+heliang666s@users.noreply.github.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
@bedevere-app
Copy link

bedevere-app bot commented Jul 1, 2025

GH-136167 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Jul 1, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 1, 2025
… empty exceptions list (pythonGH-135845)

(cherry picked from commit 0e19db6)

Co-authored-by: heliang666s <147408835+heliang666s@users.noreply.github.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
@bedevere-app
Copy link

bedevere-app bot commented Jul 1, 2025

GH-136168 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Jul 1, 2025
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.

4 participants