Skip to content

Commit

Permalink
Merge pull request #4632 from hashicorp/b-delay-heap-race
Browse files Browse the repository at this point in the history
Use eval broker lock when reading/modifying delay heap
  • Loading branch information
preetapan committed Sep 4, 2018
2 parents fd827f8 + 2d1c9d2 commit a78d0c3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions nomad/eval_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,8 @@ func (b *EvalBroker) runDelayedEvalsWatcher(ctx context.Context) {
return
case <-timerChannel:
// remove from the heap since we can enqueue it now
b.delayHeap.Remove(&evalWrapper{eval})
b.l.Lock()
b.delayHeap.Remove(&evalWrapper{eval})
b.stats.TotalWaiting -= 1
b.enqueueLocked(eval, eval.Type)
b.l.Unlock()
Expand All @@ -777,12 +777,14 @@ func (b *EvalBroker) runDelayedEvalsWatcher(ctx context.Context) {
// nextDelayedEval returns the next delayed eval to launch and when it should be enqueued.
// This peeks at the heap to return the top. If the heap is empty, this returns nil and zero time.
func (b *EvalBroker) nextDelayedEval() (*structs.Evaluation, time.Time) {
b.l.RLock()
// If there is nothing wait for an update.
if b.delayHeap.Length() == 0 {
b.l.RUnlock()
return nil, time.Time{}
}
nextEval := b.delayHeap.Peek()

b.l.RUnlock()
if nextEval == nil {
return nil, time.Time{}
}
Expand Down

0 comments on commit a78d0c3

Please sign in to comment.