Skip to content

Commit

Permalink
fix(TKC-3004): kill nested processes on timeout properly
Browse files Browse the repository at this point in the history
  • Loading branch information
rangoo94 committed Dec 20, 2024
1 parent 1c45d06 commit 63d0a03
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions cmd/testworkflow-init/orchestration/processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,14 @@ func (p *processNode) Find(pid int32) []*processNode {
}

func (p *processNode) VirtualizePath(pid int32) {
path := p.Find(pid)
if path == nil {
return
}

// Cannot virtualize itself
if len(path) == 1 {
return
}

// Virtualize recursively
for i := 1; i < len(path); i++ {
delete(path[0].nodes, path[i])
for node := range path[i].nodes {
path[0].nodes[node] = struct{}{}
for ps := range p.nodes {
if ps.pid == pid {
for sub := range ps.nodes {
p.nodes[sub] = struct{}{}
}
delete(p.nodes, ps)
} else {
ps.VirtualizePath(pid)
}
}
}
Expand Down Expand Up @@ -106,7 +99,10 @@ func (p *processNode) Resume() error {
func (p *processNode) Kill() error {
errs := make([]error, 0)
if p.pid != -1 {
return errors.Wrap((&gopsutil.Process{Pid: p.pid}).Kill(), "killing processes")
err := errors.Wrap((&gopsutil.Process{Pid: p.pid}).Kill(), "killing processes")
if err != nil {
return err
}
}
for node := range p.nodes {
err := node.Kill()
Expand Down

0 comments on commit 63d0a03

Please sign in to comment.