diff options
Diffstat (limited to 'plugin/proxy/proxy.go')
-rw-r--r-- | plugin/proxy/proxy.go | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/plugin/proxy/proxy.go b/plugin/proxy/proxy.go index f0e6eadad..7b2abd89e 100644 --- a/plugin/proxy/proxy.go +++ b/plugin/proxy/proxy.go @@ -127,14 +127,19 @@ func (p Proxy) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) ( timeout := host.FailTimeout if timeout == 0 { - timeout = 2 * time.Second + timeout = defaultFailTimeout } atomic.AddInt32(&host.Fails, 1) + fails := atomic.LoadInt32(&host.Fails) go func(host *healthcheck.UpstreamHost, timeout time.Duration) { time.Sleep(timeout) + // we may go negative here, should be rectified by the HC. atomic.AddInt32(&host.Fails, -1) + if fails%failureCheck == 0 { // Kick off healthcheck on eveyry third failure. + host.HealthCheckURL() + } }(host, timeout) } @@ -167,9 +172,6 @@ func (p Proxy) match(state request.Request) (u Upstream) { // Name implements the Handler interface. func (p Proxy) Name() string { return "proxy" } -// defaultTimeout is the default networking timeout for DNS requests. -const defaultTimeout = 5 * time.Second - func toDnstap(ctx context.Context, host string, ex Exchanger, state request.Request, reply *dns.Msg, queryEpoch, respEpoch uint64) (err error) { if tapper := dnstap.TapperFromContext(ctx); tapper != nil { // Query @@ -206,3 +208,9 @@ func toDnstap(ctx context.Context, host string, ex Exchanger, state request.Requ } return } + +const ( + defaultFailTimeout = 2 * time.Second + defaultTimeout = 5 * time.Second + failureCheck = 3 +) |