You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
net: Resolver.LookupNetIP strips IPv6 zone from resolved addresses [1.26 backport] #82551
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
gopherbot commentedon Oct 27, 2026
Change https://go.dev/cl/855082 mentions this issue:
[release-branch.go1.26] net: preserve IPv6 zone in Resolver.LookupNetIP