Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(TKC-3004): kill nested processes on timeout properly #6097

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading