Skip to content

Do not retry numeric-only getaddrinfo failures - #3535

Open
Cherith1222 wants to merge 2 commits into
python-trio:mainfrom
Cherith1222:fix/1249-numeric-getaddrinfo-no-retry
Open

Cherith1222 wants to merge 2 commits into
python-trio:mainfrom
Cherith1222:fix/1249-numeric-getaddrinfo-no-retry

Conversation

@Cherith1222

@Cherith1222 Cherith1222 commented Oct 7, 2026 •

Copy link
Copy Markdown

Summary

trio.socket.getaddrinfo retried a numeric lookup in a worker thread, or called the custom hostname resolver, after the non-blocking attempt failed with EAI_NONAME. When the caller already passed AI_NUMERICHOST|AI_NUMERICSERV, that retry is the same lookup. The EAI_NONAME error is now raised directly.

Fixes #1249.

newsfragments/1249.bugfix.rst is in the commit.

Test Plan

On Windows, Python 3.13, PYTHONPATH=src:

  • pytest src/trio/_tests/test_socket.py -k "numeric_only_flags or custom_hostname_resolver or idna" -p no:cacheprovider -q → before the change, 1 failed and 2 passed; after, 3 passed.
  • The whole src/trio/_tests/test_socket.py → 31 passed, 4 skipped (Linux-only, two --run-slow tests, and no Unix domain socket).

Not run: slow tests, the rest of the suite, the type check, and non-Windows platforms.

AI assistance

Drafted with Cursor. The account owner authorized opening this pull request. Cherith reviewed this diff and confirmed it with the person who helped draft it. There is no Co-authored-by, Reviewed-by, or Signed-off-by trailer.

When the caller already passes AI_NUMERICHOST|AI_NUMERICSERV, the non-blocking fast-path call is identical to the retry, so propagate its EAI_NONAME instead of calling the custom hostname resolver or a worker thread.

Fixes python-trio#1249.

AI-assisted (Cursor); not yet reviewed by a human.
@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00000%. Comparing base (bcc9cee) to head (e848489).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@               Coverage Diff               @@
##                 main        #3535   +/-   ##
===============================================
  Coverage   100.00000%   100.00000%           
===============================================
  Files             128          128           
  Lines           19474        19491   +17     
  Branches         1323         1323           
===============================================
+ Hits            19474        19491   +17     
Files with missing lines Coverage Δ
src/trio/_socket.py 100.00000% <ø> (ø)
src/trio/_tests/test_socket.py 100.00000% <100.00000%> (ø)

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The AssertionError only ran when the resolver was called, so codecov left that line missing. Record the call, invoke the recorder once, and assert the numeric failure does not call it again.

AI-assisted (Cursor).
@Cherith1222

Copy link
Copy Markdown
Author

The uncovered line was the raise AssertionError in the test resolver. It only runs if getaddrinfo calls the resolver, so a passing run left it out of coverage and the project check dropped below 100%.

The test now records calls, invokes that recorder once, and checks that the numeric-only EAI_NONAME path does not record another call. Locally, test_getaddrinfo_numeric_only_flags_skip_resolver passed.

Drafted with Cursor.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

trio.socket.getaddrinfo may invoke a worker thread when it doesn't need to

1 participant