Skip to content

fix(resolver): handle None result.service from getnameinfo()#12392

Open
rnagulapalle wants to merge 6 commits into
aio-libs:masterfrom
rnagulapalle:fix/resolver-service-none-mypy
Open

fix(resolver): handle None result.service from getnameinfo()#12392
rnagulapalle wants to merge 6 commits into
aio-libs:masterfrom
rnagulapalle:fix/resolver-service-none-mypy

Conversation

@rnagulapalle
Copy link
Copy Markdown

@rnagulapalle rnagulapalle commented Apr 19, 2026

What do these changes do?

Handle the rare async resolver path where aiodns / pycares returns a link-local IPv6 getnameinfo() result with service=None.

The resolver now falls back to the numeric port from the original address tuple instead of passing None to int().

Are there changes in behavior for the user?

Yes. Link-local IPv6 resolution through AsyncResolver no longer raises when result.service is None; it keeps the original port value instead.

Is it a substantial burden for the maintainers to support this?

No. The change is limited to the existing link-local IPv6 resolver branch and mirrors the fallback behavior already used by the non-link-local IPv6 and IPv4 paths, which keep address[1] as the port.

Related issue number

No linked issue.

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is .
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES/ folder
    • name it <issue_or_pr_num>.<type>.rst (e.g. 588.bugfix.rst)
    • if you don't have an issue number, change it to the pull request
      number after creating the PR
      • .bugfix: A bug fix for something the maintainers deemed an
        improper undesired behavior that got corrected to match
        pre-agreed expectations.
      • .feature: A new behavior, public APIs. That sort of stuff.
      • .deprecation: A declaration of future API removals and breaking
        changes in behavior.
      • .breaking: When something public is removed in a breaking way.
        Could be deprecated in an earlier release.
      • .doc: Notable updates to the documentation structure or build
        process.
      • .packaging: Notes for downstreams about unobvious side effects
        and tooling. Changes in the test invocation considerations and
        runtime assumptions.
      • .contrib: Stuff that affects the contributor experience. e.g.
        Running tests, building the docs, setting up the development
        environment.
      • .misc: Changes that are hard to assign to any of the above
        categories.
    • Make sure to use full sentences with correct case and punctuation.

Test plan

  • python3 -m py_compile aiohttp/resolver.py tests/test_resolver.py

N3XT3R1337 and others added 2 commits March 18, 2026 11:43
getnameinfo() returns a NameinfoResult where service is typed as
str | None. Passing None directly to int() fails mypy's arg-type
check. Fall back to the original numeric port when service is None.

Fixes mypy error: Argument 1 to "int" has incompatible type
"str | None"; expected "str | Buffer | SupportsInt | ..."
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Apr 19, 2026
@rnagulapalle
Copy link
Copy Markdown
Author

Closing — will be re-raised by Phalanx CI Fixer autonomously.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 19, 2026

Codecov Report

❌ Patch coverage is 29.62963% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.29%. Comparing base (8059959) to head (ca363eb).
⚠️ Report is 34 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
tests/test_resolver.py 28.00% 18 Missing ⚠️
aiohttp/resolver.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #12392       +/-   ##
===========================================
- Coverage   98.94%   47.29%   -51.66%     
===========================================
  Files         131      131               
  Lines       46683    46706       +23     
  Branches     2421     2421               
===========================================
- Hits        46189    22088    -24101     
- Misses        369    23996    +23627     
- Partials      125      622      +497     
Flag Coverage Δ
Autobahn 22.45% <25.92%> (+<0.01%) ⬆️
CI-GHA ?
OS-Linux ?
OS-Windows ?
OS-macOS ?
Py-3.10.11 ?
Py-3.10.20 ?
Py-3.11.15 ?
Py-3.11.9 ?
Py-3.12.10 ?
Py-3.12.13 ?
Py-3.13.13 ?
Py-3.14.4 ?
Py-3.14.5 ?
Py-3.14.5t ?
Py-pypy3.11.15-7.3.22 ?
VM-macos ?
VM-ubuntu ?
VM-windows ?
cython-coverage 37.89% <3.70%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 19, 2026

Merging this PR will not alter performance

✅ 72 untouched benchmarks
⏩ 69 skipped benchmarks1


Comparing rnagulapalle:fix/resolver-service-none-mypy (ca363eb) with master (edc1cc2)2

Open in CodSpeed

Footnotes

  1. 69 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on master (8059959) during the generation of this report, so edc1cc2 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@rnagulapalle rnagulapalle reopened this Apr 19, 2026
@webknjaz
Copy link
Copy Markdown
Member

@rnagulapalle could you use our PR template instead of replacing it?

Comment thread aiohttp/resolver.py
Comment on lines +132 to +134
int(result.service)
if result.service is not None
else address[1]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a situation where result.service != address[1]?

Resolve the resolver test conflict while keeping the upstream DNSError regression coverage.

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread tests/test_resolver.py Outdated
@Dreamsorcerer Dreamsorcerer added the pr-unfinished The PR is unfinished and may need a volunteer to complete it label May 13, 2026
@rnagulapalle
Copy link
Copy Markdown
Author

Updated the PR description to follow the repository template. Thanks for the pointer.

@github-actions github-actions Bot removed the pr-unfinished The PR is unfinished and may need a volunteer to complete it label May 16, 2026
@bdraco bdraco requested review from bdraco and Copilot May 16, 2026 20:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Fixes two bugs in AsyncResolver: an IndexError when handling aiodns.error.DNSError with a single argument, and handling of None for result.service returned by getnameinfo() for link-local IPv6 addresses.

Changes:

  • Corrected the length check from >= 1 to >= 2 when accessing exc.args[1] in DNS error handling.
  • Added a fallback to address[1] for the port when result.service is None in the link-local IPv6 path.
  • Added tests for the single-arg DNSError case and for extracting port from getnameinfo(), and updated the test fixture to accept a configurable service.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
aiohttp/resolver.py Off-by-one fix in DNSError handling and None-safe port extraction from getnameinfo().
tests/test_resolver.py New tests for the bugfixes and updated fake getnameinfo helper to accept a service argument.
CHANGES/12253.bugfix.rst News fragment describing both fixes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_resolver.py
Comment on lines +108 to +110
def __init__(self, host: str, service: str = "0") -> None:
self.node = host
self.service = None
self.service = service
Comment thread aiohttp/resolver.py
Comment on lines 115 to 117
except aiodns.error.DNSError as exc:
msg = exc.args[1] if len(exc.args) >= 1 else "DNS lookup failed"
msg = exc.args[1] if len(exc.args) >= 2 else "DNS lookup failed"
raise OSError(None, msg) from exc
@Dreamsorcerer
Copy link
Copy Markdown
Member

Updated the PR description to follow the repository template. Thanks for the pointer.

Could you also answer the inline question? I'm unclear if there should be an if condition there at all.

@Dreamsorcerer Dreamsorcerer added the pr-unfinished The PR is unfinished and may need a volunteer to complete it label May 19, 2026
@github-actions github-actions Bot removed the pr-unfinished The PR is unfinished and may need a volunteer to complete it label May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants