Skip to content

[wasi] Dns.GetHostAddressesAsync throws for an IP literal with a mismatched address family #135030

Closed

Description

@lewing

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

  1. added this to the 12.0.0 milestone on Oct 1, 2026
  2. dotnet-policy-service commented on Oct 1, 2026

    @dotnet-policy-service
    Contributor

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

  3. locked and limited conversation to collaborators on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions