fix inserting of worker tasks
when starting a new task, we do two things to keep track of tasks (in that order): * updating the 'active' file with a list of tasks with 'update_active_workers' * updating the WORKER_TASK_LIST the second also updates the status of running tasks in the file by checking if it is still running by checking the WORKER_TASK_LIST since those two things are not locked, it can happend that we update the file, and before updating the WORKER_TASK_LIST, another thread calls update_active_workers and tries to get the status from the task log, which won't have any data yet so the status is 'unknown' (we do not update that status ever, likely for performance reasons, so we have to fix this here) by switching the order of the two operations, we make sure that only tasks reach the 'active' file which are inserted in the WORKER_TASK_LIST Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
143b654550
commit
05d755b282
|
@ -418,10 +418,8 @@ impl WorkerTask {
|
|||
let logger = FileLogger::new(&path, to_stdout)?;
|
||||
nix::unistd::chown(&path, Some(backup_user.uid), Some(backup_user.gid))?;
|
||||
|
||||
update_active_workers(Some(&upid))?;
|
||||
|
||||
let worker = Arc::new(Self {
|
||||
upid,
|
||||
upid: upid.clone(),
|
||||
abort_requested: AtomicBool::new(false),
|
||||
data: Mutex::new(WorkerTaskData {
|
||||
logger,
|
||||
|
@ -430,10 +428,14 @@ impl WorkerTask {
|
|||
}),
|
||||
});
|
||||
|
||||
// scope to drop the lock again after inserting
|
||||
{
|
||||
let mut hash = WORKER_TASK_LIST.lock().unwrap();
|
||||
|
||||
hash.insert(task_id, worker.clone());
|
||||
super::set_worker_count(hash.len());
|
||||
}
|
||||
|
||||
update_active_workers(Some(&upid))?;
|
||||
|
||||
Ok(worker)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue