fix(windows): properly kill server process tree on app quit

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 <noreply@anthropic.com>
This commit is contained in:
Anand (Andy) Houston
2025-12-30 16:47:29 +08:00
parent c5ae9ad262
commit d6705fbfb5

View File

@@ -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;
}