Repository navigation
Description
Description
On WASI, Dns.GetHostAddressesAsync throws for an IP-address literal when the requested address family doesn't match the address. The synchronous Dns.GetHostAddresses returns an empty array for the same input, which is what the API is meant to do.
await Dns.GetHostAddressesAsync("127.0.0.1", AddressFamily.InterNetworkV6); // throws on WASI
Dns.GetHostAddresses("127.0.0.1", AddressFamily.InterNetworkV6); // returns []System.Net.Sockets.SocketException : Name does not resolve
at System.Net.Dns.GetHostEntryOrAddressesCore(String hostName, Boolean justAddresses, AddressFamily addressFamily, Nullable`1 activityOrDefault)
at System.Net.Dns.GetHostAddressesCore(String hostName, AddressFamily addressFamily, Nullable`1 activityOrDefault)
at System.Net.Dns.<>c.<GetHostEntryOrAddressesCoreAsync>b__41_0(Object s, NameResolutionActivity activity)
This fails System.Net.NameResolution.Tests.GetHostAddressesTest.DnsGetHostAddresses_IPStringAndIncorrectFamily_ReturnsNoIPs for the useAsync: True rows (127.0.0.1/InterNetworkV6 and ::1/InterNetwork) in the CoreCLR WASI library tests on #134813. The same suite passed with wasmtime 45/wasi-sdk 33 and fails since #134992 (wasmtime 49.0.1/wasi-sdk 34). The CI lane on main runs only smoke tests, so main doesn't show the failure.
Cause
GetHostAddresses returns parsed IP literals directly (filtered by family) on every platform. GetHostEntryOrAddressesCoreAsync only takes that shortcut when NameResolutionPal.SupportsGetNameInfo is true:
if (NameResolutionPal.SupportsGetNameInfo && IPAddress.TryParse(hostName, out IPAddress? ipAddress))
{
...
if (justReturnParsedIp)
{
return ... family == AddressFamily.Unspecified || ipAddress.AddressFamily == family ? new[] { ipAddress } : Array.Empty<IPAddress>() ...
}SupportsGetNameInfo is !OperatingSystem.IsWasi(), so on WASI the async path sends the literal to getaddrinfo with a mismatched family. wasi-libc 34 under wasmtime 49 reports that as EAI_NONAME.
Proposed fix
SupportsGetNameInfo matters only when a reverse lookup is needed. When the caller just wants the parsed IP (justReturnParsedIp), take the IP-literal path regardless:
if ((justReturnParsedIp || NameResolutionPal.SupportsGetNameInfo) && IPAddress.TryParse(hostName, out IPAddress? ipAddress))The !justReturnParsedIp case, which needs getnameinfo, still falls through to getaddrinfo on WASI as it does today. With this change GetHostAddressesAsync matches GetHostAddresses on WASI.
Note
This issue was drafted with the help of GitHub Copilot.
Activity
dotnet-policy-service commentedon Oct 1, 2026
Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.
[wasi] Quarantine async IP-literal family test on WASI
[wasi] Quarantine async IP-literal family test on WASI
[wasi] Return parsed IP literals from Dns.GetHostAddressesAsync (#135033
[wasi] Quarantine async IP-literal family test on WASI