@@ -256,6 +256,7 @@ export type CommandOptions = {
256256 noOutputTimeoutMs ?: number ;
257257 signal ?: AbortSignal ;
258258 maxOutputBytes ?: number ;
259+ killProcessTree ?: boolean ;
259260} ;
260261
261262const WINDOWS_CLOSE_STATE_SETTLE_TIMEOUT_MS = 250 ;
@@ -368,7 +369,8 @@ export async function runCommandWithTimeout(
368369) : Promise < SpawnResult > {
369370 const options : CommandOptions =
370371 typeof optionsOrTimeout === "number" ? { timeoutMs : optionsOrTimeout } : optionsOrTimeout ;
371- const { timeoutMs, cwd, input, baseEnv, env, noOutputTimeoutMs, signal } = options ;
372+ const { timeoutMs, cwd, input, baseEnv, env, noOutputTimeoutMs, signal, killProcessTree } =
373+ options ;
372374 const hasInput = input !== undefined ;
373375 const resolvedEnv = resolveCommandEnv ( { argv, baseEnv, env } ) ;
374376 const stdio = resolveCommandStdio ( { hasInput, preferInherit : true } ) ;
@@ -393,6 +395,9 @@ export async function runCommandWithTimeout(
393395 stdio,
394396 cwd,
395397 env : resolvedEnv ,
398+ // Cron shell wrappers need their own process group so timeout/abort kills
399+ // reach foreground children instead of leaving duplicate scheduled work.
400+ ...( killProcessTree && process . platform !== "win32" ? { detached : true } : { } ) ,
396401 windowsHide : invocation . windowsHide ,
397402 windowsVerbatimArguments : invocation . windowsVerbatimArguments ,
398403 ...( shouldSpawnWithShell ( { resolvedCommand : invocation . command , platform : process . platform } )
@@ -455,6 +460,19 @@ export async function runCommandWithTimeout(
455460 // Fall through to Node's direct child kill as a last resort.
456461 }
457462 }
463+ if (
464+ killProcessTree &&
465+ process . platform !== "win32" &&
466+ typeof child . pid === "number" &&
467+ child . pid > 0
468+ ) {
469+ try {
470+ process . kill ( - child . pid , "SIGKILL" ) ;
471+ return ;
472+ } catch {
473+ // Fall through to Node's direct child kill as a last resort.
474+ }
475+ }
458476 child . kill ( "SIGKILL" ) ;
459477 } ;
460478
0 commit comments