Retry dns queries with TCP if UDP has an i/o timeout

Signed-off-by: Kelly Campbell <kelly.a.campbell@gmail.com>
This commit is contained in:
Kelly Campbell 2018-11-27 11:24:32 -05:00
parent e0691e5827
commit a90e833c3b

View File

@ -144,7 +144,9 @@ func dnsQuery(fqdn string, rtype uint16, nameservers []string, recursive bool) (
udp := &dns.Client{Net: "udp", Timeout: DNSTimeout}
in, _, err = udp.Exchange(m, ns)
if err == dns.ErrTruncated {
if err == dns.ErrTruncated ||
(err != nil && strings.HasPrefix(err.Error(), "read udp") && strings.HasSuffix(err.Error(), "i/o timeout")) {
glog.V(6).Infof("UDP dns lookup failed, retrying with TCP: %v", err)
tcp := &dns.Client{Net: "tcp", Timeout: DNSTimeout}
// If the TCP request succeeds, the err will reset to nil
in, _, err = tcp.Exchange(m, ns)