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.
This commit is contained in:
Christian Schwarz 2018-10-12 22:15:07 +02:00
parent af3d96dab8
commit d584e1ac54

View File

@ -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(&copy)
a.tasksMtx.Lock()
a.tasks = copy
a.tasksMtx.Unlock()
return copy
}