Closed Bug 1462369 Opened 6 years ago Closed 6 years ago

Kill entire process tree when aborting a task

Categories

(Taskcluster :: Workers, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: pmoore, Assigned: pmoore)

References

Details

Attachments

(1 file)

In bug 1458873 we learned that calling c.Wait() (for c that is a *os/exec.Cmd) on an aborted command may never return.

The solution was to call c.Process().Wait() instead of c.Wait().

Later in bug 1462293 we realised that we should call c.Wait() after calling c.Process.Wait() if the process is not aborted, to make sure clean up is done.

We then discovered that since c.Wait() calls c.Process.Wait() internally, this results in two calls to c.Process.Wait() which causes a hang. I'll be raising a bug about this against the go standard library since the API docs don't handle this, nor mention it. Interestingly c.Wait() does ensure that it is only called once, but c.Process.Wait() has no such check, not documented caveat.

The cleanest solution to the problem is to kill the entire process tree (which is not supported by the go standard library APIs) but is supported by the taskkill.exe utility which ships with Windows. Since it is non-trivial to implement using win32 apis, I'm going to call taskkill.exe from generic-worker in order to kill the process tree.

This will allow us to return to using c.Wait() instead of c.Process.Wait(), and mean we don't need to treat abort/non-abort cases differently.
(In reply to Pete Moore [:pmoore][:pete] from comment #0)

> We then discovered that since c.Wait() calls c.Process.Wait() internally,
> this results in two calls to c.Process.Wait() which causes a hang. I'll be
> raising a bug about this against the go standard library since the API docs
> don't handle this, nor mention it. Interestingly c.Wait() does ensure that
> it is only called once, but c.Process.Wait() has no such check, not
> documented caveat.

See:
  *https://github.com/golang/go/blob/155aefe0c182f3788e44596db5f09cf94d2c6a3e/src/os/exec/exec.go#L458-L460
  * https://github.com/golang/go/blob/adcf2d59ec25e6a1f5fda7eb5c125302363657ea/src/os/exec.go#L124-L126
Assignee: nobody → pmoore
Status: NEW → ASSIGNED
Commits pushed to master at https://github.com/taskcluster/generic-worker

https://github.com/taskcluster/generic-worker/commit/325ac117fb11c33eaf143a00d400753f467cba49
Bug 1462369 - kill entire process tree on Windows when aborting a task command

https://github.com/taskcluster/generic-worker/commit/e958eae548457e8e039b420c9c467a92291b5e93
Merge pull request #91 from taskcluster/bug1462369

Bug 1462369 - kill entire process tree on Windows when aborting a task command
Released in generic-worker 10.8.2.
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Blocks: 1465113
No longer blocks: 1465113
Depends on: 1465113
Not landed in production yet, that will be done in bug 1465113.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Status: REOPENED → RESOLVED
Closed: 6 years ago6 years ago
Resolution: --- → FIXED
Component: Generic-Worker → Workers
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: