mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 16:24:19 -04:00
pkg/up: stop *all* goroutines (#1676)
Stop all goroutines after we get the stop signal.
This commit is contained in:
@@ -16,7 +16,7 @@ type Probe struct {
|
|||||||
target string
|
target string
|
||||||
|
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
inprogress bool
|
inprogress int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Func is used to determine if a target is alive. If so this function must return nil.
|
// 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 {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-p.stop:
|
case <-p.stop:
|
||||||
|
p.Lock()
|
||||||
|
p.inprogress = stop
|
||||||
|
p.Unlock()
|
||||||
return
|
return
|
||||||
case f := <-p.do:
|
case f := <-p.do:
|
||||||
p.Lock()
|
p.Lock()
|
||||||
if p.inprogress {
|
if p.inprogress == active || p.inprogress == stop {
|
||||||
p.Unlock()
|
p.Unlock()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
p.inprogress = true
|
p.inprogress = active
|
||||||
p.Unlock()
|
p.Unlock()
|
||||||
|
|
||||||
// Passed the lock. Now run f for as long it returns false. If a true is returned
|
// 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 {
|
if err := f(); err == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// TODO(miek): little bit of exponential backoff here?
|
|
||||||
time.Sleep(interval)
|
time.Sleep(interval)
|
||||||
|
p.Lock()
|
||||||
|
if p.inprogress == stop {
|
||||||
|
p.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
p.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Lock()
|
p.Lock()
|
||||||
p.inprogress = false
|
p.inprogress = idle
|
||||||
p.Unlock()
|
p.Unlock()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
idle = iota
|
||||||
|
active
|
||||||
|
stop
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user