From 41a7fe8530954e9b5de76bc1f301d7e78aeb73a4 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Mon, 10 Jun 2019 17:24:41 -0400 Subject: [PATCH] client/allocrunner: depend on internal task state Alloc runner already tracks tasks associated with alloc. Here, we become defensive by relying on the alloc runner tracked tasks, rather than depend on server never updating the job unexpectedly. --- client/allocrunner/alloc_runner.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/allocrunner/alloc_runner.go b/client/allocrunner/alloc_runner.go index e9efa120f15..544f9ba6ffa 100644 --- a/client/allocrunner/alloc_runner.go +++ b/client/allocrunner/alloc_runner.go @@ -571,11 +571,11 @@ func (ar *allocRunner) clientAlloc(taskStates map[string]*structs.TaskState) *st // Make sure we have marked the finished at for every task. This is used // to calculate the reschedule time for failed allocations. now := time.Now() - for _, task := range alloc.Job.LookupTaskGroup(alloc.TaskGroup).Tasks { - ts, ok := a.TaskStates[task.Name] + for taskName := range ar.tasks { + ts, ok := a.TaskStates[taskName] if !ok { ts = &structs.TaskState{} - a.TaskStates[task.Name] = ts + a.TaskStates[taskName] = ts } if ts.FinishedAt.IsZero() { ts.FinishedAt = now