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
serhiy-storchaka
left a comment
There was a problem hiding this comment.
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. |
…h empty exceptions list (GH-135845) (#136167) gh-135836: Fix `IndexError` in `asyncio.create_connection` with empty exceptions list (GH-135845) (cherry picked from commit 0e19db6) Co-authored-by: heliang666s <147408835+heliang666s@users.noreply.github.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org>
…h empty exceptions list (GH-135845) (#136168) gh-135836: Fix `IndexError` in `asyncio.create_connection` with empty exceptions list (GH-135845) (cherry picked from commit 0e19db6) Co-authored-by: heliang666s <147408835+heliang666s@users.noreply.github.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org>
… empty exceptions list (python#135845) Co-authored-by: Kumar Aditya <kumaraditya@python.org>
… empty exceptions list (python#135845) Co-authored-by: Kumar Aditya <kumaraditya@python.org>
… empty exceptions list (python#135845) Co-authored-by: Kumar Aditya <kumaraditya@python.org>
… empty exceptions list (python#135845) Co-authored-by: Kumar Aditya <kumaraditya@python.org>
… empty exceptions list (python#135845) Co-authored-by: Kumar Aditya <kumaraditya@python.org>
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.