mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
cmd/cli: use config timeout when checking upstream
Otherwise, for slow network connection (like plane wifi), the check may fail even though the internet is available.
This commit is contained in:
committed by
Cuong Manh Le
parent
db6e977e3a
commit
3ea69b180c
@@ -93,9 +93,12 @@ func (p *prog) checkUpstream(upstream string, uc *ctrld.UpstreamConfig) {
|
||||
}
|
||||
msg := new(dns.Msg)
|
||||
msg.SetQuestion(".", dns.TypeNS)
|
||||
|
||||
timeout := 1000 * time.Millisecond
|
||||
if uc.Timeout > 0 {
|
||||
timeout = time.Duration(uc.Timeout) * time.Millisecond
|
||||
}
|
||||
check := func() error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
uc.ReBootstrap()
|
||||
_, err := resolver.Resolve(ctx, msg)
|
||||
@@ -112,6 +115,8 @@ func (p *prog) checkUpstream(upstream string, uc *ctrld.UpstreamConfig) {
|
||||
mainLog.Load().Warn().Msg("stop leaking query")
|
||||
}
|
||||
return
|
||||
} else {
|
||||
mainLog.Load().Debug().Msgf("upstream %q is offline: %v", uc.Endpoint, err)
|
||||
}
|
||||
time.Sleep(checkUpstreamBackoffSleep)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user