From e1d80311653393ff55427ca589ec972ffec77e15 Mon Sep 17 00:00:00 2001 From: Kylejeong2 Date: Mon, 9 Feb 2026 11:44:13 -0800 Subject: [PATCH] fix: fix: detach child process to prevent double cleanup on Ctrl+C --- src/cli/dev/process.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/cli/dev/process.ts b/src/cli/dev/process.ts index c33cd67..63d23c4 100644 --- a/src/cli/dev/process.ts +++ b/src/cli/dev/process.ts @@ -73,6 +73,7 @@ export class ProcessManager implements IProcessManager { // Spawn tsx watch with the user's entrypoint this.process = spawn(process.execPath, [tsxCli, ...args], { cwd: process.cwd(), + detached: true, env: { ...process.env, AWS_LAMBDA_RUNTIME_API: this.runtimeApiUrl, @@ -179,7 +180,11 @@ export class ProcessManager implements IProcessManager { const killTimeout = setTimeout(() => { if (this.process) { console.log(chalk.yellow("⚠️ Force killing runtime process")); - this.process.kill("SIGKILL"); + try { + process.kill(-this.process.pid!, "SIGKILL"); + } catch { + this.process.kill("SIGKILL"); + } } }, 5000); @@ -190,8 +195,14 @@ export class ProcessManager implements IProcessManager { resolve(); }); - // Try graceful shutdown first - this.process.kill("SIGTERM"); + // Kill the entire process group (negative PID) so tsx watch's + // children are also cleaned up. Falls back to direct kill if + // the process group kill fails. + try { + process.kill(-this.process.pid!, "SIGTERM"); + } catch { + this.process.kill("SIGTERM"); + } }); }