Skip to content

Commit

Permalink
ignore if domain already lookup failed
Browse files Browse the repository at this point in the history
  • Loading branch information
weaving118 committed Nov 20, 2019
1 parent 1345185 commit debb7f0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/dns/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,28 +295,33 @@ func (s *Server) lookupIPInternal(domain string, option IPOption) ([]net.IP, err
}

var lastErr error
var matchedClient Client
if s.domainMatcher != nil {
idx := s.domainMatcher.Match(domain)
if idx > 0 {
ns := s.clients[s.domainIndexMap[idx]]
newError("domain matched, direct lookup ip for domain ", domain, " at ", ns.Name()).WriteToLog()
ips, err := s.queryIPTimeout(s.domainIndexMap[idx], ns, domain, option)
matchedClient = s.clients[s.domainIndexMap[idx]]
newError("domain matched, direct lookup ip for domain ", domain, " at ", matchedClient.Name()).WriteToLog()
ips, err := s.queryIPTimeout(s.domainIndexMap[idx], matchedClient, domain, option)
if len(ips) > 0 {
return ips, nil
}
if err == dns.ErrEmptyResponse {
return nil, err
}
if err != nil {
newError("failed to lookup ip for domain ", domain, " at server ", ns.Name()).Base(err).WriteToLog()
newError("failed to lookup ip for domain ", domain, " at server ", matchedClient.Name()).Base(err).WriteToLog()
lastErr = err
}
}
}

for idx, client := range s.clients {
newError("try to lookup ip for domain ", domain, " at server ", client.Name(), " idx:", idx).AtDebug().WriteToLog()
if client == matchedClient {
newError("domain ", domain, " at server ", client.Name(), " idx:", idx, " already lookup failed, just ignore").AtDebug().WriteToLog()
continue
}

newError("try to lookup ip for domain ", domain, " at server ", client.Name(), " idx:", idx).AtDebug().WriteToLog()
ips, err := s.queryIPTimeout(uint32(idx), client, domain, option)
if len(ips) > 0 {
newError("lookup ip for domain ", domain, " success: ", ips, " at server ", client.Name(), " idx:", idx).AtDebug().WriteToLog()
Expand Down

0 comments on commit debb7f0

Please sign in to comment.