diff options
author | 2018-04-13 16:01:12 +0100 | |
---|---|---|
committer | 2018-04-13 16:01:12 +0100 | |
commit | 662edf6607f6e8fb3cb65d5853642cc82a75f4f2 (patch) | |
tree | 86023bd94a3e094eeb254e0b8cd91bae41b66ea5 /plugin/pkg | |
parent | e671e22e657b2fcb1580abd311e9c340b20b9e96 (diff) | |
download | coredns-662edf6607f6e8fb3cb65d5853642cc82a75f4f2.tar.gz coredns-662edf6607f6e8fb3cb65d5853642cc82a75f4f2.tar.zst coredns-662edf6607f6e8fb3cb65d5853642cc82a75f4f2.zip |
pkg/up: stop *all* goroutines (#1676)
Stop all goroutines after we get the stop signal.
Diffstat (limited to 'plugin/pkg')
-rw-r--r-- | plugin/pkg/up/up.go | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/plugin/pkg/up/up.go b/plugin/pkg/up/up.go index 34b23fdad..4d0ec21bc 100644 --- a/plugin/pkg/up/up.go +++ b/plugin/pkg/up/up.go @@ -16,7 +16,7 @@ type Probe struct { target string sync.Mutex - inprogress bool + inprogress int } // Func is used to determine if a target is alive. If so this function must return nil. @@ -40,14 +40,17 @@ func (p *Probe) start(interval time.Duration) { for { select { case <-p.stop: + p.Lock() + p.inprogress = stop + p.Unlock() return case f := <-p.do: p.Lock() - if p.inprogress { + if p.inprogress == active || p.inprogress == stop { p.Unlock() continue } - p.inprogress = true + p.inprogress = active p.Unlock() // Passed the lock. Now run f for as long it returns false. If a true is returned @@ -57,13 +60,25 @@ func (p *Probe) start(interval time.Duration) { if err := f(); err == nil { break } - // TODO(miek): little bit of exponential backoff here? time.Sleep(interval) + p.Lock() + if p.inprogress == stop { + p.Unlock() + return + } + p.Unlock() } + p.Lock() - p.inprogress = false + p.inprogress = idle p.Unlock() }() } } } + +const ( + idle = iota + active + stop +) |