diff options
author | 2018-04-20 17:47:46 +0300 | |
---|---|---|
committer | 2018-04-20 17:47:46 +0300 | |
commit | 135377bf776295d8ef86081c1ef581e7b41d26f0 (patch) | |
tree | e09807cdfedfb7b8a6181ad660c42dd6ea0d1f78 /plugin/forward/proxy.go | |
parent | ad13d88346d3e4686d92df20efb65af8f97dd7e1 (diff) | |
download | coredns-135377bf776295d8ef86081c1ef581e7b41d26f0.tar.gz coredns-135377bf776295d8ef86081c1ef581e7b41d26f0.tar.zst coredns-135377bf776295d8ef86081c1ef581e7b41d26f0.zip |
plugin/forward: gracefull stop (#1701)
* plugin/forward: gracefull stop
- stop connection manager only when no queries in progress
* minor improvement
* prevent healthcheck on stopped proxy
* revert closing channels
* use standard context
Diffstat (limited to 'plugin/forward/proxy.go')
-rw-r--r-- | plugin/forward/proxy.go | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/plugin/forward/proxy.go b/plugin/forward/proxy.go index 3271e7dd9..8454b296d 100644 --- a/plugin/forward/proxy.go +++ b/plugin/forward/proxy.go @@ -24,6 +24,9 @@ type Proxy struct { fails uint32 avgRtt int64 + + state uint32 + inProgress int32 } // NewProxy returns a new proxy. @@ -79,15 +82,26 @@ func (p *Proxy) Down(maxfails uint32) bool { return fails > maxfails } -// close stops the health checking goroutine. +// close stops the health checking goroutine and connection manager. func (p *Proxy) close() { - p.probe.Stop() - p.transport.Stop() + if atomic.CompareAndSwapUint32(&p.state, running, stopping) { + p.probe.Stop() + } + if atomic.LoadInt32(&p.inProgress) == 0 { + p.checkStopTransport() + } } // start starts the proxy's healthchecking. func (p *Proxy) start(duration time.Duration) { p.probe.Start(duration) } +// checkStopTransport checks if stop was requested and stops connection manager +func (p *Proxy) checkStopTransport() { + if atomic.CompareAndSwapUint32(&p.state, stopping, stopped) { + p.transport.Stop() + } +} + const ( dialTimeout = 4 * time.Second timeout = 2 * time.Second @@ -95,3 +109,9 @@ const ( minTimeout = 10 * time.Millisecond hcDuration = 500 * time.Millisecond ) + +const ( + running = iota + stopping + stopped +) |