Skip to content

Commit

Permalink
ensure task is not nil before goroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
sonroyaalmerol committed Dec 8, 2024
1 parent dcbc8fd commit 59f50c2
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions internal/backend/backup/jobrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,28 @@ func RunBackup(job *store.Job, storeInstance *store.Store, waitChan chan struct{
return nil, fmt.Errorf("RunBackup: proxmox-backup-client start error (%s) -> %w", cmd.String(), err)
}

log.Printf("Waiting for task: %s\n", job.ID)
select {
case <-taskChan:
case <-watchCtx.Done():
case <-time.After(time.Second * 60):
_ = cmd.Process.Kill()
if agentMount != nil {
agentMount.Unmount()
}

return nil, fmt.Errorf("RunBackup: timeout, task not found")
}

if task == nil {
_ = cmd.Process.Kill()
if agentMount != nil {
agentMount.Unmount()
}

return nil, fmt.Errorf("RunBackup: task not found")
}

go func(currJob *store.Job, currTask *store.Task) {
defer func() {
if waitChan != nil {
Expand Down Expand Up @@ -222,28 +244,6 @@ func RunBackup(job *store.Job, storeInstance *store.Store, waitChan chan struct{
}
}(job, task)

log.Printf("Waiting for task: %s\n", job.ID)
select {
case <-taskChan:
case <-watchCtx.Done():
case <-time.After(time.Second * 60):
_ = cmd.Process.Kill()
if agentMount != nil {
agentMount.Unmount()
}

return nil, fmt.Errorf("RunBackup: timeout, task not found")
}

if task == nil {
_ = cmd.Process.Kill()
if agentMount != nil {
agentMount.Unmount()
}

return nil, fmt.Errorf("RunBackup: task not found")
}

job.LastRunUpid = &task.UPID
job.LastRunState = &task.Status

Expand Down

0 comments on commit 59f50c2

Please sign in to comment.