Hi Nuts,
net.LookupHost is taking a long time (up to 5 seconds) to resolve localhost, where I expect it to be instant. At other times it can take anywhere from 1-100ms, but it seems to reliably return a result shortly after 5 seconds.
The details:
* I'm doing local development inside a docker container (alpine linux: `docker run alpine sh`). Outside of this environment I can't seem to easily get the problem to manifest, but I haven't tried hard.
* The problem manifests as many things having an additional random amount of latency of order 100ms-5s.
* Inside the container, various services are talking to each other through URLs which read `http://localhost:...`
* Resolv.conf has `nameserver 8.8.8.8` which may or may not be unreachable at different times. If it is unreachable, then it takes 5 seconds to resolve localhost.
* I'm on a slow mobile network, so I hit this frequently.
* I experience 5 second timeouts even on fast networks where the resolver should be reachable, though this could perhaps be explained by an out-of-date resolv.conf inside the docker container.
* Tweaking GODEBUG=netdns= to either go or cgo seems to fix the problem.
* The presence or absense of an empty /etc/nsswitch.conf has no effect.
* An empty resolv.conf still selects "dns,files" but then returns a result fast (in microseconds).
My test program:
func main() {
start := time.Now()
_, err := net.LookupHost("localhost")
if err != nil {
log.Fatal(err)
}
log.Printf("Took %v", time.Since(start))
}