Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
call libc::res_init() in response to DNS failures
Go's DNS resolution often defers to the libc implementation, and glibc's resolver has a serious bug: https://sourceware.org/bugzilla/show_bug.cgi?id=984 It will cache the contents of /etc/resolv.conf, which can put the client in a state where all DNS requests fail forever after a network change. The conditions where Go calls into libc are complicated and platform-specific, and the resolver cache involves thread-local state, so repros tend to be inconsistent. But when you hit this on your laptop on the subway or whatever, the effect is that everything is broken until you restart the process. One way to fix this would be to force using the pure-Go resolver (net.DefaultResolver.PreferGo = true), which refreshes /etc/resolv.conf every 5 seconds. I'm wary of doing that, because the Go devs went through an enormous amount of trouble to enable cgo fallback, for various platform- and environment-specific reasons. See all the comments in net/conf.go::initConfVal() and net/conf.go::hostLookupOrder() in the standard library. Instead, we're trying the same workaround that the Rust standard library chose, where we call libc::res_init() after DNS failures. See rust-lang/rust#41570. The downside here is that we have to remember to do this after we make network calls, and that we have to use cgo in the build, but the upside is that it should never break a DNS environment that was working before.
- Loading branch information