Skip to content

Do not retry numeric-only getaddrinfo failures - #3535

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

Cherith1222 wants to merge 1 commit 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

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 99.99487%. Comparing base (bcc9cee) to head (80343b2).

Files with missing lines Patch % Lines
src/trio/_tests/test_socket.py 91.66667% 1 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                  @@
##                 main       #3535         +/-   ##
====================================================
- Coverage   100.00000%   99.99487%   -0.00513%     
====================================================
  Files             128         128                 
  Lines           19474       19485         +11     
  Branches         1323        1323                 
====================================================
+ Hits            19474       19484         +10     
- Misses              0           1          +1     
Files with missing lines Coverage Δ
src/trio/_socket.py 100.00000% <ø> (ø)
src/trio/_tests/test_socket.py 99.84663% <91.66667%> (-0.15337%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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