From c5672e57bdc3a9ed0be2b50301ba370dfa99be78 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Tue, 17 Feb 2026 14:47:47 -0800 Subject: [PATCH] cleanup --- src/server/apps.ts | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/server/apps.ts b/src/server/apps.ts index cc65a1f..96eee00 100644 --- a/src/server/apps.ts +++ b/src/server/apps.ts @@ -490,14 +490,29 @@ function handleHealthCheckFailure(app: App) { } async function killStaleProcesses() { - const result = Bun.spawnSync(['lsof', '-ti', `:${MIN_PORT - 1}-${MAX_PORT}`]) - const output = result.stdout.toString().trim() - if (!output) return + const pids = new Set() - const pids = output.split('\n').map(Number).filter(pid => pid && pid !== process.pid) - if (pids.length === 0) return + // Find processes listening on our port range + const lsof = Bun.spawnSync(['lsof', '-ti', `:${MIN_PORT - 1}-${MAX_PORT}`]) + const lsofOutput = lsof.stdout.toString().trim() + if (lsofOutput) { + for (const pid of lsofOutput.split('\n').map(Number)) { + if (pid && pid !== process.pid) pids.add(pid) + } + } - hostLog(`Found ${pids.length} stale process(es) on ports ${MIN_PORT - 1}-${MAX_PORT}`) + // Find orphaned "bun run toes" child app processes + const pgrep = Bun.spawnSync(['pgrep', '-f', 'bun run toes']) + const pgrepOutput = pgrep.stdout.toString().trim() + if (pgrepOutput) { + for (const pid of pgrepOutput.split('\n').map(Number)) { + if (pid && pid !== process.pid) pids.add(pid) + } + } + + if (pids.size === 0) return + + hostLog(`Found ${pids.size} stale process(es)`) for (const pid of pids) { try { process.kill(pid, 'SIGKILL')