Skip to content

net: Resolver.LookupNetIP strips IPv6 zone from resolved addresses [1.27 backport] #82552

Open

Description

@gopherbot

@database64128 requested issue #81601 to be considered for backport to the next 1.27 minor release.

@gopherbot please open backport issues.

Today the net package only provides a basic Happy Eyeballs v1 implementation when connecting to a domain name TCP host. Applications that care about responsiveness and want a browser-like behavior will have to implement Happy Eyeballs v2 or v3 in their own code. An important part of that implementation is hostname resolution, so let's look at what the net package provides.

Both Happy Eyeballs v2 and v3 require resolving IPv4 and IPv6 addresses separately, in parallel after the resolution delay. This means we can't use Resolver.LookupHost or Resolver.LookupIPAddr, as neither of them takes a network parameter.

We also want to make sure .local mDNS hostnames are handled correctly, which means preserving the IPv6 zone identifier as returned by the CGO resolver. This makes Resolver.LookupIP unsuitable, as the net.IP type inherently cannot represent IPv6 zone identifiers.

These requirements leave us with Resolver.LookupNetIP as the only available API for resolving hostnames for Happy Eyeballs v2 and v3, but only if this fix is applied. The fix itself does not change any name resolution logic. Only the final type conversion is modified to not drop the zone identifier. And it only touches code inside Resolver.LookupIP and Resolver.LookupNetIP, neither of which is called by anything in the standard library other than their tests, so it should be very unlikely to cause any regression outside of callers of these exported functions.

As for possible workarounds, I could think of the following:

  • Check .local suffix and fall back to Dialer.DialContext (Happy Eyeballs v1). Not ideal and only works for TCP-based protocols.
  • Just let it fall back to IPv4. Depending on how the platform handles a connect to an invalid IPv6 link-local address, this may or may not introduce a fixed delay (300ms by default) to .local hosts. This also won't work in IPv6-only networks.
  • Use //go:linkname to call the unexported Resolver.lookupIPAddr and build with linker flag -checklinkname=0.
  • Copy the whole CGO resolver implementation from the standard library.

Activity

  1. added this to the Go1.27.4 milestone on Oct 26, 2026
  2. JunyangShao commented on Oct 27, 2026

    @JunyangShao
    Contributor

    @database64128 ping on backport CLs, thanks.

  3. gopherbot commented on Oct 27, 2026

    @gopherbot
    ContributorAuthor

    Change https://go.dev/cl/855181 mentions this issue: [release-branch.go1.27] net: preserve IPv6 zone in Resolver.LookupNetIP

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

    CherryPickApprovedUsed during the release process for point releases

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions