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: DNS lookup API with timeouts #4890
Currently, there's no way to do a DNS lookup with a deadline or duration that the request must finish within. This would be useful when the user wants to control DNS lookups at a finer grained level separate from connections and requests. There is a lookupHostDeadline function in net/lookup.go, but it is not exposed to the user. lookupHostDeadline has a TODO inside it to bring the deadlining down into the name resolution functions themselves, so solving this issue could involve solving that. Even an exposed API with the TODO in place would allow users to benefit from future fixes. This is related to the now closed issue #2631.
There are nine Lookup functions in package net. This would mean adding nine new functions, taking timeouts. To understand your motivation for wanting this, were you actually hitting problems with the number of fds or threads for the DNS/cgo calls? And which OS? On Linux at least we could use getaddrinfo_a (see http://www.imperialviolet.org/2005/06/01/asynchronous-dns-lookups-with-glibc.html and http://www.kernel.org/doc/man-pages/online/pages/man3/getaddrinfo_a.3.html) but even that API doesn't really seem to do timeouts efficiently, probably because the underlying NSS / resolver(3) mechanisms don't really support timeouts. Your best bet probably is to not use the system's DNS facilities and use a pure Go DNS resolver (maybe https://github.com/miekg/dns, which seems popular), where you'll have more control.
Labels changed: added priority-someday, removed priority-triage.
Status changed to Thinking.
This issue was closed.