mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-22 00:13:52 +01: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 {
|
||||
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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user