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.
// Dial optionally specifies an alternate dialer for use by// Go's built-in DNS resolver to make TCP and UDP connections// to DNS services. The host in the address parameter will// always be a literal IP address and not a host name, and the// port in the address parameter will be a literal port number// and not a service name.// If the Conn returned is also a PacketConn, sent and received DNS// messages must adhere to RFC 1035 section 4.2.1, "UDP usage".// Otherwise, DNS messages transmitted over Conn must adhere// to RFC 7766 section 5, "Transport Protocol Selection".// If nil, the default dialer is used.Dialfunc(ctx context.Context, network, addressstring) (Conn, error)
There's is one hardcoded call to net.DialUDPhere which appears to be the source of the additional connections.
What did you expect to see?
I expect to see the Dial function used for all connections made by the pure Go resolver.
What did you see instead?
I see that the Dial function is only used in some cases.
CL 500576 fixes the issue by using net.Resolver.Dial in all cases.
For context, this change is important for targets with limited networking capabilities (e.g. GOOS=wasip1). It means that users can provide their own Dial function to make use of the pure Go resolver. At the moment the hardcoded net.DialUDP call makes the pure Go resolver off limits for these targets.
There was some concern in the CL about whether making this change for all targets would break code in the wild. I'm submitting it as a bug report so we can discuss here instead.
This has the additional benefit of threading the lookup context through to the underlying dialer.
If we're concerned about breaking code in the wild, we could instead opt-in by target, and take this path for GOOS=wasip1 only for now (since it has limited networking capabilities, and DialUDP always fails).
The runtime.GOOS == "wasip1" guard was just a simple fix idea, but I agree with @ianlancetaylor that having a per platform behaviour in this case is not ideal.
I think that this hook should be named something like IsAddrReachable, so that the intention is clear.
And probably it should use the netip.Addr at this point.
// IsAddrReachable is used for address sorting by the go resolver.// When this field is equal to nil, the default dialer is being used. addr is considered reachable,// when the default dialer sucesfully establishes a UDP connection to addr.IsAddrReachablefunc(ctx context.Context, addr netip.Addr) (local netip.Addr, reachablebool)