Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
net: LookupAddr force use of cgo no matter what #12190
While investigating #12189, found that the new Go 1.5 implementation of LookupAddr always calls cgo first, even when the DNS configuration on the machine does not merit it, and even when GODEBUG=netdns=go is set in the environment. (If the tree was built with CGO_ENABLED=0 ./make.bash then the cgo call fails quickly and the code falls back to the pure Go version. But it is still called.)
Previous releases of Go had no cgo implementation of LookupAddr, so they always used the pure Go version.
Using cgo unconditionally means that a thread is held by a blocked call (except when CGO_ENABLED=0 of course), where in previous releases it was only a goroutine being held. This is a significant resource increase.
It's even worse that setting GODEBUG, which is supposed to keep cgo from being used, does nothing in this case.
LookupAddr should respect GODEBUG and even without GODEBUG it should not use cgo if the resolver config can be handled by pure Go.
Thanks for the investigation and sorry to trouble you. The change looks good to me even though it appends a trailing dot unconditionally when GODEBUG=netdns=cgo and the name is stored in local database such as /etc/hosts. I now think it's fine because /etc/hosts could be considered as a substitute for some DNS RRs; A, AAAA, PTR (and CNAME on some platform), and actually mDNS speaker implementations use it as a source of RRs.