fix(windows): use execSync for reliable process termination

Address code review feedback:
- Replace async spawn() with sync execSync() to ensure taskkill
  completes before app exits
- Add try/catch error handling for permission/invalid-PID errors
- Add helpful error logging for debugging

🤖 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:56:31 +08:00
parent d6705fbfb5
commit 784d7fc059

View File

@@ -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';
@@ -598,9 +598,14 @@ app.on('before-quit', () => {
if (serverProcess && serverProcess.pid) {
console.log('[Electron] Stopping server...');
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()]);
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');
}