diff --git a/resolver.go b/resolver.go index c91f12d..a641f13 100644 --- a/resolver.go +++ b/resolver.go @@ -45,11 +45,18 @@ func (r *Resolver) Lookup(net string, req *dns.Msg) (message *dns.Msg, err error logger.Warn("error:%s", err.Error()) return } + // If SERVFAIL happen, should return immediately and try another upstream resolver. + // However, other Error code like NXDOMAIN is an clear response stating + // that it has been verified no such domain existas and ask other resolvers + // would make no sense. See more about #20 if r != nil && r.Rcode != dns.RcodeSuccess { logger.Warn("%s failed to get an valid answer on %s", qname, nameserver) - return + if r.Rcode == dns.RcodeServerFailure { + return + } + } else { + logger.Debug("%s resolv on %s (%s) ttl: %d", UnFqdn(qname), nameserver, net, rtt) } - logger.Debug("%s resolv on %s (%s) ttl: %d", UnFqdn(qname), nameserver, net, rtt) select { case res <- r: default: