From d584e1ac541c43de40dbcb7137fbcd89c54f4ec4 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Fri, 12 Oct 2018 22:15:07 +0200 Subject: [PATCH] daemon/job/active: fix race in updateTasks If concurrent updates strictly modify *different* members of the tasks struct, the copying + lock-drop still constitutes a race condition: The last updater always wins and sets tasks to its copy + changes. This eliminates the other updater's changes. --- daemon/job/active.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/daemon/job/active.go b/daemon/job/active.go index 0d78abb..482b368 100644 --- a/daemon/job/active.go +++ b/daemon/job/active.go @@ -43,16 +43,14 @@ type activeSideTasks struct { func (a *ActiveSide) updateTasks(u func(*activeSideTasks)) activeSideTasks { a.tasksMtx.Lock() + defer a.tasksMtx.Unlock() var copy activeSideTasks copy = a.tasks - a.tasksMtx.Unlock() if u == nil { return copy } u(©) - a.tasksMtx.Lock() a.tasks = copy - a.tasksMtx.Unlock() return copy }