Merge pull request #326 from andydataguy/fix/windows-orphaned-server-processes

fix(windows): properly kill server process tree on app quit
This commit is contained in:
Web Dev Cody
2025-12-30 10:07:10 -05:00
committed by GitHub

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