From 88ad13ee7ba7957a6d1756e994b707d6f7402e2a Mon Sep 17 00:00:00 2001 From: Tam Nhu Tran Date: Thu, 12 Feb 2026 07:17:03 +0700 Subject: [PATCH] fix(cursor): kill orphaned daemon on timeout and fix exit codes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MEDIUM fixes: - Kill orphaned process when health check times out after 30s - Prevents zombie processes from consuming resources LOW fixes: - Return exit code 1 for unknown cursor subcommands (was 0) - Simplify exit handler dead code branch (else if code !== null → else) --- src/commands/cursor-command.ts | 3 ++- src/cursor/cursor-daemon.ts | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/commands/cursor-command.ts b/src/commands/cursor-command.ts index 2385a3be..99cd7551 100644 --- a/src/commands/cursor-command.ts +++ b/src/commands/cursor-command.ts @@ -48,7 +48,8 @@ export async function handleCursorCommand(args: string[]): Promise { default: console.error(fail(`Unknown subcommand: ${subcommand}`)); console.error(''); - return handleHelp(); + handleHelp(); + return 1; } } diff --git a/src/cursor/cursor-daemon.ts b/src/cursor/cursor-daemon.ts index 0f016677..07243a4d 100644 --- a/src/cursor/cursor-daemon.ts +++ b/src/cursor/cursor-daemon.ts @@ -205,6 +205,14 @@ export async function startDaemon( if (await isDaemonRunning(config.port)) { safeResolve({ success: true, pid: proc.pid }); } else if (attempts >= maxAttempts) { + // Kill orphaned process + if (proc.pid) { + try { + process.kill(proc.pid, 'SIGTERM'); + } catch { + /* already dead */ + } + } safeResolve({ success: false, error: 'Daemon did not start within 30 seconds', @@ -230,7 +238,7 @@ export async function startDaemon( success: false, error: 'Daemon process exited unexpectedly with code 0', }); - } else if (code !== null) { + } else { safeResolve({ success: false, error: `Daemon process exited with code ${code}`,