-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
gh-135836: Fix IndexError in asyncio.create_connection with empty exceptions list #135845
Conversation
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.
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 |
Changed :func: to double backticks to fix Sphinx reference error
There was a problem hiding this 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.
Misc/NEWS.d/next/Library/2025-06-23-11-04-25.gh-issue-135836.-C-c4v.rst
Outdated
Show resolved
Hide resolved
Please don't forget about test. |
I think this pr is ready for merge. cc @serhiy-storchaka @ZeroIntensity |
…e synchronous and check correct error message
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Thanks @heliang666s for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
… 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>
GH-136167 is a backport of this pull request to the 3.14 branch. |
… 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>
GH-136168 is a backport of this pull request to the 3.13 branch. |
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.