[Android] Fix DNS localhost subdomain resolution with IPv6 on Android#125478
[Android] Fix DNS localhost subdomain resolution with IPv6 on Android#125478simonrozsival wants to merge 1 commit intodotnet:mainfrom
Conversation
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
There was a problem hiding this comment.
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
localhostwithInterNetworkV6fails withHostNotFound, retry withip6-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
RespectsAddressFamilytests 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 (localhost → ip6-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>
6816840 to
6fdaf5c
Compare
|
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
|
||
| // Android's default /etc/hosts maps ::1 to "ip6-localhost" instead of "localhost", | ||
| // which causes getaddrinfo("localhost", AF_INET6) to fail with EAI_NONAME. | ||
| private const string AndroidIPv6Localhost = "ip6-localhost"; |
There was a problem hiding this comment.
I'm wondering if we should leave it as general fallback
My host file on Linux looks similar
cat /etc/hosts
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
ping6 localhost
ping6: localhost: Address family for hostname not supported
Alternatively, if IPv6 resolution for localhost fails, we can fail the other lookups as well, e.g. update the test to deal with it. Any thoughts on this @dotnet/ncl ?
Fix DNS localhost subdomain tests with AddressFamily on Android
Fixes #124751
Problem
The
DnsGetHostEntry_LocalhostSubdomain_RespectsAddressFamilyandDnsGetHostAddresses_LocalhostSubdomain_RespectsAddressFamilytests 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 sameAddressFamily. On Android, the second step fails forInterNetworkV6because Android's default/etc/hostsmaps::1toip6-localhostinstead oflocalhost:This causes
getaddrinfo("localhost", AF_INET6)to returnEAI_NONAME.Fix
When the localhost fallback fails with
InterNetworkV6on Android, retry the resolution using"ip6-localhost"— Android's default hostname for the IPv6 loopback address.The fallback chain becomes:
getaddrinfo("test.localhost", AF_INET6)→ fails → existing subdomain fallbackgetaddrinfo("localhost", AF_INET6)→ fails on Android → new: Android IPv6 fallbackgetaddrinfo("ip6-localhost", AF_INET6)→ succeedsThis is applied to both the sync (
GetHostEntryOrAddressesCore) and async (GetAddrInfoWithTelemetryAsync) code paths.Testing
RespectsAddressFamilytest cases[ActiveIssue]annotations for DNS localhost subdomain tests with AddressFamily fail on Android #124751 are removed from both test methods