Skip to content
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

net: 1.19 DNS lookups broken on Windows if standard library built with CGO_ENABLED=0 #53490

Closed
ianlancetaylor opened this issue Jun 21, 2022 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@ianlancetaylor
Copy link
Member

This bug is about the changes in Go 1.19 for DNS lookups on WIndows: https://go.dev/cl/409234 for #33097.

If the standard library is built with CGO_ENABLED=0, then in 1.18 we will still use the standard library on Windows, by calling functions like syscall.GetAddrInfoW. In both 1.18 and 1.19 building with CGO_ENABLED=0 will set netGo = true and will then set confVal.netGo = true. In 1.18 this has no real effect. In 1.19 this will mean that confVal.hostLookupOrder will return hostLookupDNS on Windows. That in turn means that (*Resolver).preferGoOverWindows will return true. That means that we will use the Go DNS routines, not the Windows functions.

Note that this can't be overridden by setting GODEBUG=netdns=cgo, as once netGo is set at initialization time everything else follows. This is a reasonable choice on Unix systems where building with CGO_ENABLED=0 means that the cgo functions are simply not available, but it's not a reasonable choice on Windows where the functions are always available.

One user-visible effect is that, since the Go lookup code on Windows has no way of looking at a /etc/hosts equivalent, looking up the address of localhost will fail.

We should make sure that Windows DNS functions will do the right thing when built with CGO_ENABLED=0 on Windows. I think they should default to using the Windows functions as before. That choice can be overridden with GODEBUG=netdns=go or by building with -tags=purego.

Or perhaps here is a different approach we could take, but definitely by default looking up localhost should work.

CC @bradfitz

@ianlancetaylor ianlancetaylor added NeedsFix The path to resolution is known, but the work has not been done. release-blocker labels Jun 21, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.19 milestone Jun 21, 2022
@ianlancetaylor ianlancetaylor self-assigned this Jun 21, 2022
@ianlancetaylor
Copy link
Member Author

I think I have a simple fix.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/413458 mentions this issue: net: don't set netGo = true on Windows with no cgo

@gopherbot gopherbot moved this to Done in Release Blockers Jun 22, 2022
jproberts pushed a commit to jproberts/go that referenced this issue Aug 10, 2022
Windows can call the C DNS lookup routines even without cgo,
so don't force it to use the Go routines in that scenario.

No test because the test requires building the tools with CGO_ENABLED=0.

For golang#33097
Fixes golang#53490

Change-Id: I3595a68e788be0d3bbd1bbd431836aca20a7d757
Reviewed-on: https://go-review.googlesource.com/c/go/+/413458
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
@golang golang locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
Status: Done
Development

No branches or pull requests

2 participants