Skip to content

Commit 867e796

Browse files
authored
lock allocstate before adding task event (#31)
We don't lock the alloc state before adding a task event. This can result in a panic when we emit allocation metrics if it happens concurrently, because the length of the slice isn't atomically updated with the contents so we end up indexing an event that's been added before the slice is valid.
1 parent 13916a7 commit 867e796

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

allocrunnersim/allocrunnersim.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,10 @@ func (ar *simulatedAllocRunner) stopAll() {
376376
event.PopulateEventDisplayMessage()
377377
taskStates[task.Name].Events = append(taskStates[task.Name].Events, event)
378378

379+
ar.allocStateLock.Lock()
379380
ar.allocState.TaskStates[task.Name].FinishedAt = time.Now()
380381
ar.allocState.TaskStates[task.Name].State = structs.TaskStateDead
382+
ar.allocStateLock.Unlock()
381383
}
382384
ar.updateAllocAndSendUpdate(taskStates)
383385

0 commit comments

Comments
 (0)