Skip to content

Commit

Permalink
fix: unable to terminate process when cancelling a task
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Jun 19, 2023
1 parent 94f5d1d commit c85c10a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 8 additions & 10 deletions sys_exec/sys_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ func killProcessWithTimeout(p *process.Process, timeout time.Duration, killFunc
}
time.Sleep(1 * time.Second)
}
return forceKillProcess(p)
return killProcess(p, true)
}

func killProcessRecursive(p *process.Process, force bool) (err error) {
// children processes
cps, err := p.Children()
if err != nil {
return killProcess(p)
return killProcess(p, force)
}

// iterate children processes
Expand All @@ -67,15 +67,13 @@ func killProcessRecursive(p *process.Process, force bool) (err error) {
return nil
}

func killProcess(p *process.Process) (err error) {
if err := p.Terminate(); err != nil {
return trace.TraceError(err)
func killProcess(p *process.Process, force bool) (err error) {
if force {
err = p.Kill()
} else {
err = p.Terminate()
}
return nil
}

func forceKillProcess(p *process.Process) (err error) {
if err := p.Kill(); err != nil {
if err != nil {
return trace.TraceError(err)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion task/handler/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (r *Runner) Cancel() (err error) {
// kill process
opts := &sys_exec.KillProcessOptions{
Timeout: r.svc.GetCancelTimeout(),
Force: false,
Force: true,
}
if err := sys_exec.KillProcess(r.cmd, opts); err != nil {
return err
Expand Down

0 comments on commit c85c10a

Please sign in to comment.