-
Notifications
You must be signed in to change notification settings - Fork 18k
net: Resolver doesn't use provided Dial function in all cases #60712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If I replace the hardcoded -c, err = DialUDP("udp", nil, &dst)
+c, err = r.dial(ctx, "udp", dst.IP.String()) 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 This approach was suggested by @mateusz834: if runtime.GOOS == "wasip1" {
c, err = r.dial(ctx, "udp", dst.IP.String())
} else {
c, err = DialUDP("udp", nil, &dst)
} @ianlancetaylor suggested that we might instead require an additional hook: type Resolver struct {
Dial func(ctx context.Context, network, address string) (Conn, error)
// Extra hook:
DialUDP func(ctx context.Context, network, address string) (Conn, error)
} or something like this: type Resolver struct {
Dial func(ctx context.Context, network, address string) (Conn, error)
// Extra hook:
UDPConnect func(ctx context.Context, *UDPAddr) (*UDPAddr, bool)
} |
Change https://go.dev/cl/500576 mentions this issue: |
The I think that this hook should be named something like type Resolver struct {
// 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.
IsAddrReachable func(ctx context.Context, addr netip.Addr) (local netip.Addr, reachable bool)
} |
CL 502315 improved the situation for wasip1 by addressing the panic in |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
The
net.Resolver
accepts an optionalDial
function that says the following:I created a script that logs
Dial
calls when using the pure Go resolver: https://go.dev/play/p/0O_ARZyK2eGIf I run this script locally, I see something like this:
However, if I run the script with strace, I see that Go is making additional connections some other way:
There's is one hardcoded call to
net.DialUDP
here 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.Additional context
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 ownDial
function to make use of the pure Go resolver. At the moment the hardcodednet.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.
cc
GOOS=wasip1
maintainers: @achille-roussel @johanbrandhorst @Pryzcc those that commented on CL 500576: @mateusz834 @ianlancetaylor
The text was updated successfully, but these errors were encountered: