From 81e0bad739f2ce21ad8326a36aa865d3379f2378 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 10 Feb 2025 20:34:37 -0500 Subject: [PATCH] increase failure count for all queries with no answer --- cmd/cli/dns_proxy.go | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/cmd/cli/dns_proxy.go b/cmd/cli/dns_proxy.go index 24660f8..0bc042e 100644 --- a/cmd/cli/dns_proxy.go +++ b/cmd/cli/dns_proxy.go @@ -531,19 +531,6 @@ func (p *prog) proxy(ctx context.Context, req *proxyRequest) *proxyResponse { ctx = context.WithValue(ctx, ctrld.ClientInfoCtxKey{}, req.ci) } answer, err := resolve1(upstream, upstreamConfig, msg) - if err != nil { - ctrld.Log(ctx, mainLog.Load().Error().Err(err), "failed to resolve query") - isNetworkErr := errNetworkError(err) - if isNetworkErr { - p.um.increaseFailureCount(upstream) - } - // For timeout error (i.e: context deadline exceed), force re-bootstrapping. - var e net.Error - if errors.As(err, &e) && e.Timeout() { - upstreamConfig.ReBootstrap() - } - return nil - } // if we have an answer, we should reset the failure count // we dont use reset here since we dont want to prevent failure counts from being incremented if answer != nil { @@ -551,8 +538,24 @@ func (p *prog) proxy(ctx context.Context, req *proxyRequest) *proxyResponse { p.um.failureReq[upstream] = 0 p.um.down[upstream] = false p.um.mu.Unlock() + return answer } - return answer + + ctrld.Log(ctx, mainLog.Load().Error().Err(err), "failed to resolve query") + + // increase failure count when there is no answer + // rehardless of what kind of error we get + p.um.increaseFailureCount(upstream) + + if err != nil { + // For timeout error (i.e: context deadline exceed), force re-bootstrapping. + var e net.Error + if errors.As(err, &e) && e.Timeout() { + upstreamConfig.ReBootstrap() + } + } + + return nil } for n, upstreamConfig := range upstreamConfigs { if upstreamConfig == nil {