mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-04 01:07:49 +02:00
fix failure count on OS retry
This commit is contained in:
@@ -509,8 +509,8 @@ func (p *prog) proxy(ctx context.Context, req *proxyRequest) *proxyResponse {
|
|||||||
staleAnswer = answer
|
staleAnswer = answer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resolve1 := func(n int, upstreamConfig *ctrld.UpstreamConfig, msg *dns.Msg) (*dns.Msg, error) {
|
resolve1 := func(upstream string, upstreamConfig *ctrld.UpstreamConfig, msg *dns.Msg) (*dns.Msg, error) {
|
||||||
ctrld.Log(ctx, mainLog.Load().Debug(), "sending query to %s: %s", upstreams[n], upstreamConfig.Name)
|
ctrld.Log(ctx, mainLog.Load().Debug(), "sending query to %s: %s", upstream, upstreamConfig.Name)
|
||||||
dnsResolver, err := ctrld.NewResolver(upstreamConfig)
|
dnsResolver, err := ctrld.NewResolver(upstreamConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctrld.Log(ctx, mainLog.Load().Error().Err(err), "failed to create resolver")
|
ctrld.Log(ctx, mainLog.Load().Error().Err(err), "failed to create resolver")
|
||||||
@@ -525,17 +525,17 @@ func (p *prog) proxy(ctx context.Context, req *proxyRequest) *proxyResponse {
|
|||||||
}
|
}
|
||||||
return dnsResolver.Resolve(resolveCtx, msg)
|
return dnsResolver.Resolve(resolveCtx, msg)
|
||||||
}
|
}
|
||||||
resolve := func(n int, upstreamConfig *ctrld.UpstreamConfig, msg *dns.Msg) *dns.Msg {
|
resolve := func(upstream string, upstreamConfig *ctrld.UpstreamConfig, msg *dns.Msg) *dns.Msg {
|
||||||
if upstreamConfig.UpstreamSendClientInfo() && req.ci != nil {
|
if upstreamConfig.UpstreamSendClientInfo() && req.ci != nil {
|
||||||
ctrld.Log(ctx, mainLog.Load().Debug(), "including client info with the request")
|
ctrld.Log(ctx, mainLog.Load().Debug(), "including client info with the request")
|
||||||
ctx = context.WithValue(ctx, ctrld.ClientInfoCtxKey{}, req.ci)
|
ctx = context.WithValue(ctx, ctrld.ClientInfoCtxKey{}, req.ci)
|
||||||
}
|
}
|
||||||
answer, err := resolve1(n, upstreamConfig, msg)
|
answer, err := resolve1(upstream, upstreamConfig, msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctrld.Log(ctx, mainLog.Load().Error().Err(err), "failed to resolve query")
|
ctrld.Log(ctx, mainLog.Load().Error().Err(err), "failed to resolve query")
|
||||||
isNetworkErr := errNetworkError(err)
|
isNetworkErr := errNetworkError(err)
|
||||||
if isNetworkErr {
|
if isNetworkErr {
|
||||||
p.um.increaseFailureCount(upstreams[n])
|
p.um.increaseFailureCount(upstream)
|
||||||
}
|
}
|
||||||
// For timeout error (i.e: context deadline exceed), force re-bootstrapping.
|
// For timeout error (i.e: context deadline exceed), force re-bootstrapping.
|
||||||
var e net.Error
|
var e net.Error
|
||||||
@@ -548,8 +548,8 @@ func (p *prog) proxy(ctx context.Context, req *proxyRequest) *proxyResponse {
|
|||||||
// we dont use reset here since we dont want to prevent failure counts from being incremented
|
// we dont use reset here since we dont want to prevent failure counts from being incremented
|
||||||
if answer != nil {
|
if answer != nil {
|
||||||
p.um.mu.Lock()
|
p.um.mu.Lock()
|
||||||
p.um.failureReq[upstreams[n]] = 0
|
p.um.failureReq[upstream] = 0
|
||||||
p.um.down[upstreams[n]] = false
|
p.um.down[upstream] = false
|
||||||
p.um.mu.Unlock()
|
p.um.mu.Unlock()
|
||||||
}
|
}
|
||||||
return answer
|
return answer
|
||||||
@@ -568,7 +568,7 @@ func (p *prog) proxy(ctx context.Context, req *proxyRequest) *proxyResponse {
|
|||||||
ctrld.Log(ctx, logger, "DNS loop detected")
|
ctrld.Log(ctx, logger, "DNS loop detected")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
answer := resolve(n, upstreamConfig, req.msg)
|
answer := resolve(upstreams[n], upstreamConfig, req.msg)
|
||||||
if answer == nil {
|
if answer == nil {
|
||||||
if serveStaleCache && staleAnswer != nil {
|
if serveStaleCache && staleAnswer != nil {
|
||||||
ctrld.Log(ctx, mainLog.Load().Debug(), "serving stale cached response")
|
ctrld.Log(ctx, mainLog.Load().Debug(), "serving stale cached response")
|
||||||
@@ -641,7 +641,7 @@ func (p *prog) proxy(ctx context.Context, req *proxyRequest) *proxyResponse {
|
|||||||
// attempt query to OS resolver while as a retry catch all
|
// attempt query to OS resolver while as a retry catch all
|
||||||
if upstreams[0] != upstreamOS {
|
if upstreams[0] != upstreamOS {
|
||||||
ctrld.Log(ctx, mainLog.Load().Debug(), "attempting query to OS resolver as a retry catch all")
|
ctrld.Log(ctx, mainLog.Load().Debug(), "attempting query to OS resolver as a retry catch all")
|
||||||
answer := resolve(0, osUpstreamConfig, req.msg)
|
answer := resolve(upstreamOS, osUpstreamConfig, req.msg)
|
||||||
if answer != nil {
|
if answer != nil {
|
||||||
ctrld.Log(ctx, mainLog.Load().Debug(), "OS resolver retry query successful")
|
ctrld.Log(ctx, mainLog.Load().Debug(), "OS resolver retry query successful")
|
||||||
res.answer = answer
|
res.answer = answer
|
||||||
|
|||||||
Reference in New Issue
Block a user