mirror of
https://git.proxmox.com/git/proxmox
synced 2025-10-04 15:15:35 +00:00
rest-server: close race window when updating worker task count
this mimics how the count is updated when spawning a new task - the lock scope needs to cover the count update itself, else there's a race when multiple worker's log their result at the same time.. Co-developed-by: Dominik Csapak <d.csapak@proxmox.com> Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
4e51ac3527
commit
57c8242dc2
@ -923,6 +923,7 @@ impl WorkerTask {
|
|||||||
set_worker_count(hash.len());
|
set_worker_count(hash.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this wants to access WORKER_TASK_LIST, so we need to drop the lock above
|
||||||
let res = setup.update_active_workers(Some(&upid));
|
let res = setup.update_active_workers(Some(&upid));
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
// needed to undo the insertion into WORKER_TASK_LIST above
|
// needed to undo the insertion into WORKER_TASK_LIST above
|
||||||
@ -1022,8 +1023,11 @@ impl WorkerTask {
|
|||||||
self.log_message(state.result_text());
|
self.log_message(state.result_text());
|
||||||
|
|
||||||
WORKER_TASK_LIST.lock().unwrap().remove(&self.upid.task_id);
|
WORKER_TASK_LIST.lock().unwrap().remove(&self.upid.task_id);
|
||||||
|
// this wants to access WORKER_TASK_LIST, so we need to drop the lock above
|
||||||
let _ = self.setup.update_active_workers(None);
|
let _ = self.setup.update_active_workers(None);
|
||||||
set_worker_count(WORKER_TASK_LIST.lock().unwrap().len());
|
// re-acquire the lock and hold it while updating the count
|
||||||
|
let lock = WORKER_TASK_LIST.lock().unwrap();
|
||||||
|
set_worker_count(lock.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Log a message.
|
/// Log a message.
|
||||||
|
Loading…
Reference in New Issue
Block a user