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: GODEBUG=netdns=cgo doesn't override netgo build tag #57203

Closed
roidelapluie opened this issue Dec 9, 2022 · 3 comments
Closed

net: GODEBUG=netdns=cgo doesn't override netgo build tag #57203

roidelapluie opened this issue Dec 9, 2022 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@roidelapluie
Copy link

roidelapluie commented Dec 9, 2022

What version of Go are you using (go version)?

$ go version
go 1.19.3

(this is Prometheus, cross compiled from linux)

Does this issue reproduce with the latest release?

yes

What did you do?

Used GODEBUG=netdns=cgo

https://gist.github.com/roidelapluie/8a87428055a77bfc3a08dc427e595599

What did you expect to see?

Using C for DNS, because the C library routines are always available on Windows.

What did you see instead?

It is using the cgo resolved, which fails to resolve e.g. localhost.

@roidelapluie roidelapluie changed the title net: Can't force cgo resolution on Windonws net: Can't force cgo resolution on Windows Dec 9, 2022
@seankhliao seankhliao changed the title net: Can't force cgo resolution on Windows net: GODEBUG=netdns=cgo doesn't override netgo build tag Dec 9, 2022
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 9, 2022
@mateusz834
Copy link
Member

mateusz834 commented Dec 9, 2022

I feel like that is the way it is supposed to work.
If you compile with netgo flag, then you cannot change the resolver to a cgo one.

Edit:
But I think that you can easily cross-compile from linux to windows without -tags netgo, it should use then the "cgo" version. This should work on gotip, probably related to: #53490

@roidelapluie
Copy link
Author

Yes but I would expect to be able to make the choice at runtime

@rsc
Copy link
Contributor

rsc commented Dec 9, 2022

The netgo build tag means do not compile cgo into the program at all.
If you want cgo linked into your program, don't use -tags netgo.
If you want a program linked with cgo to ignore using cgo by default, then you could put this at the start of func main:

os.Setenv("GODEBUG", "netdns=go,"+os.Getenv("GODEBUG"))

If #56986 is accepted, you could write that as //go:debug netdns=go instead.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants