From d6705fbfb56fb48d9eec816f479e852bfed7f92b Mon Sep 17 00:00:00 2001 From: "Anand (Andy) Houston" Date: Tue, 30 Dec 2025 16:47:29 +0800 Subject: [PATCH] fix(windows): properly kill server process tree on app quit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Windows, serverProcess.kill() doesn't reliably terminate Node.js child processes. This causes orphaned node processes to hold onto ports 3007/3008, preventing the app from starting on subsequent launches. Use taskkill with /f /t flags to force-kill the entire process tree on Windows, while keeping SIGTERM for macOS/Linux where it works correctly. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- apps/ui/src/main.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/ui/src/main.ts b/apps/ui/src/main.ts index 4e112f25..d227866f 100644 --- a/apps/ui/src/main.ts +++ b/apps/ui/src/main.ts @@ -595,9 +595,15 @@ app.on('window-all-closed', () => { }); app.on('before-quit', () => { - if (serverProcess) { + if (serverProcess && serverProcess.pid) { console.log('[Electron] Stopping server...'); - serverProcess.kill(); + if (process.platform === 'win32') { + // Windows: use taskkill with /t to kill entire process tree + // This prevents orphaned node processes when closing the app + spawn('taskkill', ['/f', '/t', '/pid', serverProcess.pid.toString()]); + } else { + serverProcess.kill('SIGTERM'); + } serverProcess = null; }