mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-16 15:26:40 +00:00
Fix linter
This commit is contained in:
@@ -102,56 +102,57 @@ func (u *upstreamResolver) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
||||
|
||||
for _, upstream := range u.upstreamServers {
|
||||
var (
|
||||
err error
|
||||
t time.Duration
|
||||
rm *dns.Msg
|
||||
exchangeErr error
|
||||
t time.Duration
|
||||
rm *dns.Msg
|
||||
)
|
||||
|
||||
upstreamExchangeClient := &dns.Client{}
|
||||
if runtime.GOOS != "ios" {
|
||||
ctx, cancel := context.WithTimeout(u.ctx, u.upstreamTimeout)
|
||||
rm, t, err = upstreamExchangeClient.ExchangeContext(ctx, r, upstream)
|
||||
rm, t, exchangeErr = upstreamExchangeClient.ExchangeContext(ctx, r, upstream)
|
||||
cancel()
|
||||
} else {
|
||||
upstreamHost, _, err := net.SplitHostPort(upstream)
|
||||
if err != nil {
|
||||
log.Errorf("error while parsing upstream host: %s", err)
|
||||
return
|
||||
}
|
||||
upstreamIP := net.ParseIP(upstreamHost)
|
||||
if u.lNet.Contains(upstreamIP) || net.IP.IsPrivate(upstreamIP) {
|
||||
log.Debugf("using private client to query upstream: %s", upstream)
|
||||
upstreamExchangeClient = u.getClientPrivate()
|
||||
}
|
||||
rm, t, err = upstreamExchangeClient.Exchange(r, upstream)
|
||||
rm, t, exchangeErr = upstreamExchangeClient.Exchange(r, upstream)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if err == context.DeadlineExceeded || isTimeout(err) {
|
||||
log.WithError(err).WithField("upstream", upstream).
|
||||
if exchangeErr != nil {
|
||||
if exchangeErr == context.DeadlineExceeded || isTimeout(exchangeErr) {
|
||||
log.WithError(exchangeErr).WithField("upstream", upstream).
|
||||
Warn("got an error while connecting to upstream")
|
||||
continue
|
||||
}
|
||||
u.failsCount.Add(1)
|
||||
log.WithError(err).WithField("upstream", upstream).
|
||||
log.WithError(exchangeErr).WithField("upstream", upstream).
|
||||
Error("got other error while querying the upstream")
|
||||
return
|
||||
}
|
||||
|
||||
if rm == nil {
|
||||
log.WithError(err).WithField("upstream", upstream).
|
||||
log.WithError(exchangeErr).WithField("upstream", upstream).
|
||||
Warn("no response from upstream")
|
||||
return
|
||||
}
|
||||
// those checks need to be independent of each other due to memory address issues
|
||||
if !rm.Response {
|
||||
log.WithError(err).WithField("upstream", upstream).
|
||||
log.WithError(exchangeErr).WithField("upstream", upstream).
|
||||
Warn("no response from upstream")
|
||||
return
|
||||
}
|
||||
|
||||
log.Tracef("took %s to query the upstream %s", t, upstream)
|
||||
|
||||
err = w.WriteMsg(rm)
|
||||
err := w.WriteMsg(rm)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("got an error while writing the upstream resolver response")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user