(child, signal)
| 24 | } |
| 25 | |
| 26 | export function terminateWindowsProcessTree(child, signal) { |
| 27 | const taskkill = spawn( |
| 28 | "taskkill.exe", |
| 29 | ["/pid", String(child.pid), "/t", "/f"], |
| 30 | { |
| 31 | env: windowsTerminationEnvironment(), |
| 32 | shell: false, |
| 33 | stdio: "ignore", |
| 34 | windowsHide: true, |
| 35 | }, |
| 36 | ); |
| 37 | |
| 38 | return new Promise((resolve, reject) => { |
| 39 | taskkill.once("error", (error) => { |
| 40 | if (child.exitCode === null && child.signalCode === null) { |
| 41 | child.kill(signal); |
| 42 | } |
| 43 | reject( |
| 44 | new Error( |
| 45 | `failed to terminate Windows process tree for PID ${child.pid}: ${error.message}`, |
| 46 | ), |
| 47 | ); |
| 48 | }); |
| 49 | |
| 50 | taskkill.once("close", (code, taskkillSignal) => { |
| 51 | if (code === 0) { |
| 52 | resolve(); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | if (child.exitCode === null && child.signalCode === null) { |
| 57 | child.kill(signal); |
| 58 | } |
| 59 | const outcome = taskkillSignal |
| 60 | ? `signal ${taskkillSignal}` |
| 61 | : `exit code ${code}`; |
| 62 | reject( |
| 63 | new Error( |
| 64 | `failed to terminate Windows process tree for PID ${child.pid}: taskkill ${outcome}`, |
| 65 | ), |
| 66 | ); |
| 67 | }); |
| 68 | }); |
| 69 | } |
| 70 | |
| 71 | // A container PID 1 may not promptly reap group-killed descendants. Those |
| 72 | // zombies hold no resources but keep kill(-pgid, 0) successful, so Linux uses |
no test coverage detected