Skip to content

Commit 23a427c

Browse files
committed
fix(sentinel): kill process group on probe timeout to prevent pipe hang
Use process.kill(-pid, SIGKILL) to terminate the entire process group, ensuring child processes spawned by the shell are also killed. Falls back to proc.kill(9) if process group kill fails.
1 parent cbf73bc commit 23a427c

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

‎src/workflow/sentinel/probe-runner.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,18 @@ export class ProbeRunner {
5656
});
5757

5858
// Hard timeout: kill the probe if it exceeds the deadline.
59-
// Use SIGKILL to ensure the process (and any children sharing the pipe)
60-
// is terminated immediately — SIGTERM may leave orphaned children that
61-
// keep the pipe open and block stream reads.
62-
const timeoutId = setTimeout(() => proc.kill(9), this.timeoutMs);
59+
// Kill the entire process group (negative PID) with SIGKILL to ensure
60+
// child processes spawned by the shell are also terminated — otherwise
61+
// orphaned children keep the pipe open and block stream reads.
62+
const timeoutId = setTimeout(() => {
63+
try {
64+
process.kill(-proc.pid, "SIGKILL");
65+
} catch {
66+
// Process group kill may fail (e.g. process already exited, or not
67+
// a process group leader). Fall back to killing the direct child.
68+
try { proc.kill(9); } catch { /* already dead */ }
69+
}
70+
}, this.timeoutMs);
6371

6472
// Read stdout and stderr concurrently to avoid deadlocks.
6573
// readBoundedDrain reads up to maxBytes into memory, then drains the

0 commit comments

Comments
 (0)