Replace killProcessTree references to shell-utils with process/kill-tree (#55213)

* Replace killProcessTree references to shell-utils with process/kill-tree

* Address grace timeout comment

* Align with existing process kill behavior

* bash: fail stop without pid

* bash: lazy-load kill tree on stop

---------

Co-authored-by: Jacob Tomlinson <jtomlinson@nvidia.com>
This commit is contained in:
mappel-nv
2026-03-27 07:25:56 -04:00
committed by GitHub
parent d80b67124b
commit 9d58f9e24f
4 changed files with 128 additions and 35 deletions

View File

@@ -1,11 +1,11 @@
import { afterEach, expect, test } from "vitest";
import { killProcessTree } from "../process/kill-tree.js";
import {
getFinishedSession,
getSession,
resetProcessRegistryForTests,
} from "./bash-process-registry.js";
import { createExecTool } from "./bash-tools.exec.js";
import { killProcessTree } from "./shell-utils.js";
const BACKGROUND_HOLD_CMD = 'node -e "setTimeout(() => {}, 5000)"';
const ABORT_SETTLE_MS = process.platform === "win32" ? 200 : 25;

View File

@@ -1,4 +1,3 @@
import { spawn } from "node:child_process";
import fs from "node:fs";
import path from "node:path";
@@ -166,27 +165,3 @@ export function sanitizeBinaryOutput(text: string): string {
}
return chunks.join("");
}
export function killProcessTree(pid: number): void {
if (process.platform === "win32") {
try {
spawn("taskkill", ["/F", "/T", "/PID", String(pid)], {
stdio: "ignore",
detached: true,
});
} catch {
// ignore errors if taskkill fails
}
return;
}
try {
process.kill(-pid, "SIGKILL");
} catch {
try {
process.kill(pid, "SIGKILL");
} catch {
// process already dead
}
}
}