mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-08 10:46:06 +00:00
fix: SIGKILL escalation in killProcessTree + unit tests
Remaining review follow-ups:
- killProcessTree now escalates to SIGKILL after 500ms if SIGTERM
doesn't kill the process (same pattern as killTrackedProcesses).
Covers orphan cleanup and dev/local mode tree kill.
- Added unit tests for both new modules:
- processTracker.test.ts (6 tests): track/remove on exit/error,
kill running processes, SIGKILL escalation for SIGTERM-resistant
processes, idempotency.
- orphanCleanup.test.ts (5 tests): tree kill with children,
SIGKILL escalation, non-existent PID handling, orphan detection
returns 0 when clean.
This commit is contained in:
@@ -41,17 +41,27 @@ export function killProcessTree(pid: number, signal: NodeJS.Signals = "SIGTERM")
|
||||
if (process.platform === "win32") return;
|
||||
|
||||
const descendants = getDescendants(pid);
|
||||
for (const child of descendants.reverse()) {
|
||||
const allPids = [...descendants.reverse(), pid];
|
||||
|
||||
for (const p of allPids) {
|
||||
try {
|
||||
process.kill(child, signal);
|
||||
process.kill(p, signal);
|
||||
} catch {
|
||||
// Already exited.
|
||||
}
|
||||
}
|
||||
try {
|
||||
process.kill(pid, signal);
|
||||
} catch {
|
||||
// Already exited.
|
||||
|
||||
// Escalate to SIGKILL after a short grace period for any survivors.
|
||||
if (signal !== "SIGKILL") {
|
||||
setTimeout(() => {
|
||||
for (const p of allPids) {
|
||||
try {
|
||||
process.kill(p, "SIGKILL");
|
||||
} catch {
|
||||
// Already exited.
|
||||
}
|
||||
}
|
||||
}, 500).unref();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user