diff --git a/apps/ui/src/main.ts b/apps/ui/src/main.ts index 4e112f25..b2f7bd86 100644 --- a/apps/ui/src/main.ts +++ b/apps/ui/src/main.ts @@ -6,7 +6,7 @@ */ import path from 'path'; -import { spawn, ChildProcess } from 'child_process'; +import { spawn, execSync, ChildProcess } from 'child_process'; import fs from 'fs'; import crypto from 'crypto'; import http, { Server } from 'http'; @@ -595,9 +595,20 @@ 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') { + try { + // Windows: use taskkill with /t to kill entire process tree + // This prevents orphaned node processes when closing the app + // Using execSync to ensure process is killed before app exits + execSync(`taskkill /f /t /pid ${serverProcess.pid}`, { stdio: 'ignore' }); + } catch (error) { + console.error('[Electron] Failed to kill server process:', (error as Error).message); + } + } else { + serverProcess.kill('SIGTERM'); + } serverProcess = null; }