mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-04 12:13:09 +00:00
- Add 7 test cases covering SIGTERM/SIGKILL escalation, timer cleanup, default and custom grace periods, and already-exited process edge case - Add timer.unref() to prevent keeping event loop alive during shutdown - Add comment explaining 10s grace period in headless-executor timeout
22 lines
685 B
TypeScript
22 lines
685 B
TypeScript
/**
|
|
* Process management utilities
|
|
*/
|
|
|
|
import { ChildProcess } from 'child_process';
|
|
|
|
/**
|
|
* Kill process with SIGTERM, escalating to SIGKILL if it doesn't exit.
|
|
* Uses exitCode === null (not proc.killed) to check if process is still running,
|
|
* since proc.killed only indicates a signal was sent, not that the process exited.
|
|
*/
|
|
export function killWithEscalation(proc: ChildProcess, gracePeriodMs = 3000): void {
|
|
proc.kill('SIGTERM');
|
|
const timer = setTimeout(() => {
|
|
if (proc.exitCode === null) {
|
|
proc.kill('SIGKILL');
|
|
}
|
|
}, gracePeriodMs);
|
|
timer.unref(); // Don't keep event loop alive just for escalation
|
|
proc.once('exit', () => clearTimeout(timer));
|
|
}
|