Skip to content

[Android] Fix DNS localhost subdomain resolution with IPv6 on Android#125478

Open
simonrozsival wants to merge 2 commits intodotnet:mainfrom
simonrozsival:fix/124751-dns-localhost-android
Open

[Android] Fix DNS localhost subdomain resolution with IPv6 on Android#125478
simonrozsival wants to merge 2 commits intodotnet:mainfrom
simonrozsival:fix/124751-dns-localhost-android

Conversation

@simonrozsival
Copy link
Member

Fix DNS localhost subdomain tests with AddressFamily on Android

Fixes #124751

Problem

The DnsGetHostEntry_LocalhostSubdomain_RespectsAddressFamily and DnsGetHostAddresses_LocalhostSubdomain_RespectsAddressFamily tests consistently fail on Android.

The RFC 6761 localhost subdomain fallback (introduced in #123076) resolves "test.localhost" by first trying the OS resolver, then falling back to resolving plain "localhost" with the same AddressFamily. On Android, the second step fails for InterNetworkV6 because Android's default /etc/hosts maps ::1 to ip6-localhost instead of localhost:

127.0.0.1       localhost
::1             ip6-localhost

This causes getaddrinfo("localhost", AF_INET6) to return EAI_NONAME.

Fix

When the localhost fallback fails with InterNetworkV6 on Android, retry the resolution using "ip6-localhost" — Android's default hostname for the IPv6 loopback address.

The fallback chain becomes:

  1. getaddrinfo("test.localhost", AF_INET6) → fails → existing subdomain fallback
  2. getaddrinfo("localhost", AF_INET6) → fails on Android → new: Android IPv6 fallback
  3. getaddrinfo("ip6-localhost", AF_INET6) → succeeds

This is applied to both the sync (GetHostEntryOrAddressesCore) and async (GetAddrInfoWithTelemetryAsync) code paths.

Testing

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

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

Fixes Android-specific failures in RFC 6761 *.localhost subdomain resolution when an AddressFamily filter is applied (notably InterNetworkV6), by adding an Android IPv6 localhost fallback that retries using ip6-localhost if localhost IPv6 resolution fails.

Changes:

  • Add Android-only IPv6 fallback: if resolving localhost with InterNetworkV6 fails with HostNotFound, retry with ip6-localhost (sync + async paths).
  • Refactor async localhost-subdomain fallback to use helper local functions that include the Android retry behavior.
  • Re-enable the Android variants of the RespectsAddressFamily tests by removing [ActiveIssue] annotations.

Reviewed changes

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

File Description
src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs Adds Android IPv6 retry (localhostip6-localhost) for InterNetworkV6 when localhost-subdomain fallback resolves plain localhost; applied to sync + async telemetry path.
src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs Removes Android [ActiveIssue] to re-enable localhost subdomain AddressFamily test coverage.
src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostAddressesTest.cs Removes Android [ActiveIssue] to re-enable localhost subdomain AddressFamily test coverage.

On Android, getaddrinfo("localhost", AF_INET6) fails with EAI_NONAME
because the default /etc/hosts maps ::1 to "ip6-localhost" instead of
"localhost". This causes the RFC 6761 localhost subdomain fallback to
fail when InterNetworkV6 is requested.

Add an Android-specific catch in the fallback path: when IPv6 localhost
resolution fails with HostNotFound, retry with "ip6-localhost".

Fixes dotnet#124751

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival force-pushed the fix/124751-dns-localhost-android branch from 6816840 to 6fdaf5c Compare March 12, 2026 08:35
@simonrozsival simonrozsival marked this pull request as ready for review March 12, 2026 08:39
@simonrozsival simonrozsival requested review from Copilot and rzikm March 12, 2026 08:39
Copy link
Contributor

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

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

@simonrozsival
Copy link
Member Author

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Remove the OperatingSystem.IsAndroid() guard so the ip6-localhost
IPv6 fallback applies on any system where /etc/hosts maps ::1 to
ip6-localhost instead of localhost (e.g. Android, some Linux distros).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival
Copy link
Member Author

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@wfurt wfurt left a comment

Choose a reason for hiding this comment

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

LGTM

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DNS localhost subdomain tests with AddressFamily fail on Android

4 participants