diff --git a/nomad/blocked_evals.go b/nomad/blocked_evals.go index 47801a18f..14efe9911 100644 --- a/nomad/blocked_evals.go +++ b/nomad/blocked_evals.go @@ -336,6 +336,7 @@ func (b *BlockedEvals) UnblockFailed() { if eval.TriggeredBy == structs.EvalTriggerMaxPlans { unblock = append(unblock, eval) delete(b.captured, id) + delete(b.jobs, eval.JobID) } } @@ -343,10 +344,15 @@ func (b *BlockedEvals) UnblockFailed() { if eval.TriggeredBy == structs.EvalTriggerMaxPlans { unblock = append(unblock, eval) delete(b.escaped, id) + delete(b.jobs, eval.JobID) + b.stats.TotalEscaped -= 1 } } - b.evalBroker.EnqueueAll(unblock) + if l := len(unblock); l > 0 { + b.stats.TotalBlocked -= l + b.evalBroker.EnqueueAll(unblock) + } } // GetDuplicates returns all the duplicate evaluations and blocks until the diff --git a/nomad/blocked_evals_test.go b/nomad/blocked_evals_test.go index 75d8207f6..35b55a4a1 100644 --- a/nomad/blocked_evals_test.go +++ b/nomad/blocked_evals_test.go @@ -404,6 +404,12 @@ func TestBlockedEvals_UnblockFailed(t *testing.T) { // Trigger an unblock fail blocked.UnblockFailed() + // Verify UnblockFailed caused the eval to be immediately unblocked + blockedStats := blocked.Stats() + if blockedStats.TotalBlocked != 0 && blockedStats.TotalEscaped != 0 { + t.Fatalf("bad: %#v", blockedStats) + } + testutil.WaitForResult(func() (bool, error) { // Verify Unblock caused an enqueue brokerStats := broker.Stats()