mirror of
https://github.com/zrepl/zrepl.git
synced 2025-06-12 12:57:28 +02:00
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:
parent
af3d96dab8
commit
d584e1ac54
@ -43,16 +43,14 @@ type activeSideTasks struct {
|
|||||||
|
|
||||||
func (a *ActiveSide) updateTasks(u func(*activeSideTasks)) activeSideTasks {
|
func (a *ActiveSide) updateTasks(u func(*activeSideTasks)) activeSideTasks {
|
||||||
a.tasksMtx.Lock()
|
a.tasksMtx.Lock()
|
||||||
|
defer a.tasksMtx.Unlock()
|
||||||
var copy activeSideTasks
|
var copy activeSideTasks
|
||||||
copy = a.tasks
|
copy = a.tasks
|
||||||
a.tasksMtx.Unlock()
|
|
||||||
if u == nil {
|
if u == nil {
|
||||||
return copy
|
return copy
|
||||||
}
|
}
|
||||||
u(©)
|
u(©)
|
||||||
a.tasksMtx.Lock()
|
|
||||||
a.tasks = copy
|
a.tasks = copy
|
||||||
a.tasksMtx.Unlock()
|
|
||||||
return copy
|
return copy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user