From 1dcde75d30830d72efc21947bb334bb31b0781f4 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Wed, 19 Sep 2018 17:32:50 -0700 Subject: [PATCH] ar: lock around accessing tasks Specify that Alloc() does not return updated task states. --- client/allocrunnerv2/alloc_runner.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/allocrunnerv2/alloc_runner.go b/client/allocrunnerv2/alloc_runner.go index 73e5773cd..b4b47326f 100644 --- a/client/allocrunnerv2/alloc_runner.go +++ b/client/allocrunnerv2/alloc_runner.go @@ -206,7 +206,8 @@ func (ar *allocRunner) runImpl() <-chan struct{} { return waitCh } -// Alloc returns the current allocation being run by this runner. +// Alloc returns the current allocation being run by this runner as sent by the +// server. This view of the allocation does not have updated task states. func (ar *allocRunner) Alloc() *structs.Allocation { ar.allocLock.RLock() defer ar.allocLock.RUnlock() @@ -277,6 +278,7 @@ func (ar *allocRunner) TaskStateUpdated(taskName string, state *structs.TaskStat } // Gather the state of the other tasks + ar.tasksLock.RLock() states := make(map[string]*structs.TaskState, len(ar.tasks)) for name, tr := range ar.tasks { if name == taskName { @@ -285,6 +287,7 @@ func (ar *allocRunner) TaskStateUpdated(taskName string, state *structs.TaskStat states[name] = tr.TaskState() } } + ar.tasksLock.RUnlock() // Get the client allocation calloc := ar.clientAlloc(states)