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: cannot enforce usage of netgo for DNS resolution #33904

Open
subsr97 opened this issue Aug 28, 2019 · 3 comments

Comments

@subsr97
Copy link

commented Aug 28, 2019

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

$ go version
go version go1.12.9 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/test/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/test/work"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build754748271=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Tried to enforce the usage of netgo for DNS resolution with the netgo tag.

In some machines, even when netgo tag is used during compilation and when having GODEBUG=netdns=go in the environment, cgo is being used for DNS resolution.

These machines have options edns0 in their /etc/resolv.conf.

I'm trying to enforce the usage of netgo for DNS resolution to overcome an issue similar to this one. The known workaround is to use netgo for DNS resolution.

lookuphost_example.go - https://play.golang.org/p/CgzqQXsSgvd
Build Command: go build -tags netdns lookuphost_example.go

What did you expect to see?

I expected Go to use netdns for DNS resolution.

➜  export GODEBUG=netdns=2

➜  ./lookuphost_example 
go package net: dynamic selection of DNS resolver
go package net: hostLookupOrder(www.google.com) = files,dns
[216.58.197.36 2404:6800:4007:807::2004]

What did you see instead?

In machines with options edns0 in /etc/resolv.conf, it still uses cgo for DNS resolution.

$ export GODEBUG=netdns=2

$ ./lookuphost_example 
go package net: dynamic selection of DNS resolver
go package net: hostLookupOrder(www.google.com) = cgo
[216.58.197.36 2404:6800:4007:807::2004]

After removing the edns0 entry from resolv.conf, the issue is resolved.

$ ./lookuphost_example 
go package net: dynamic selection of DNS resolver
go package net: hostLookupOrder(www.google.com) = files,dns
[216.58.197.36 2404:6800:4007:807::2004]

@ianlancetaylor ianlancetaylor changed the title Cannot enforce usage of netgo for DNS resolution net: cannot enforce usage of netgo for DNS resolution Aug 28, 2019

@ianlancetaylor ianlancetaylor added this to the Go1.14 milestone Aug 28, 2019

@tomocy

This comment has been minimized.

Copy link
Contributor

commented Sep 3, 2019

Can I tackle this?

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Sep 3, 2019

@tomocy You are certainly welcome to look at this issue. The first step is to understand what is happening. There are cases of resolv.conf entries that we don't handle, and for those cases we deliberately fall back to calling C code because anything else would be incorrect. That may be what is happening here. In that case we need to decide whether there is anything to change here.

@tomocy

This comment has been minimized.

Copy link
Contributor

commented Sep 22, 2019

I inspected and I also think that this behavior is caused by dnsConfig.unknownOpt which is set true because edns0 option is unknown there.
This therefore lets (*conf).hostLookupOrder return hostLookupCgo here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.