filter some upstream errors

master
dingjun 4 years ago
parent 072b83c49d
commit 7e84fc502a

@ -36,12 +36,23 @@ func getResponseFromUpstream(msg *dns.Msg, upstreams []*url.URL) (*dns.Msg, erro
}(up) }(up)
} }
var errmsg *dns.Msg
for i := 0; i < len(upstreams); i++ {
select { select {
case <-ctx.Done(): case <-ctx.Done():
return nil, errors.New("time out") return nil, errors.New("time out")
case m := <-resch: case m := <-resch:
if m.MsgHdr.Rcode == dns.RcodeSuccess {
return m, nil return m, nil
} }
errmsg = m
}
}
if errmsg != nil {
return errmsg, nil
}
return nil, errors.New("empty result")
} }
func queryUpstream(msg *dns.Msg, upstream *url.URL) (*dns.Msg, error) { func queryUpstream(msg *dns.Msg, upstream *url.URL) (*dns.Msg, error) {

Loading…
Cancel
Save