Skip to content

Commit

Permalink
allochealth: Fix when check health preceeds task health
Browse files Browse the repository at this point in the history
Fix a bug where if the alloc check becomes healthy before the task health, the
alloc may never be considered healthy.
  • Loading branch information
Mahmood Ali committed May 13, 2020
1 parent d4e4563 commit 22b65f2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions client/allochealth/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ func (t *Tracker) setTaskHealth(healthy, terminal bool) {
}

// setCheckHealth is used to mark the checks as either healthy or unhealthy.
func (t *Tracker) setCheckHealth(healthy bool) {
// returns true if health is propagated and no more health monitoring is needed
func (t *Tracker) setCheckHealth(healthy bool) bool {
t.l.Lock()
defer t.l.Unlock()

Expand All @@ -220,7 +221,7 @@ func (t *Tracker) setCheckHealth(healthy bool) {

// Only signal if we are healthy and so is the tasks
if !t.checksHealthy {
return
return false
}

select {
Expand All @@ -230,6 +231,7 @@ func (t *Tracker) setCheckHealth(healthy bool) {

// Shutdown the tracker
t.cancelFn()
return true
}

// markAllocStopped is used to mark the allocation as having stopped.
Expand Down Expand Up @@ -379,7 +381,12 @@ OUTER:
allocReg = newAllocReg
}
case <-healthyTimer.C:
t.setCheckHealth(true)
if t.setCheckHealth(true) {
// final health set and propagated
return
}
// tasks are unhealthy, reset and wait until all is healthy
primed = false
}

if allocReg == nil {
Expand Down

0 comments on commit 22b65f2

Please sign in to comment.