mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 09:13:08 +00:00
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:
@@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { spawn, ChildProcess } from 'child_process';
|
import { spawn, execSync, ChildProcess } from 'child_process';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import http, { Server } from 'http';
|
import http, { Server } from 'http';
|
||||||
@@ -598,9 +598,14 @@ app.on('before-quit', () => {
|
|||||||
if (serverProcess && serverProcess.pid) {
|
if (serverProcess && serverProcess.pid) {
|
||||||
console.log('[Electron] Stopping server...');
|
console.log('[Electron] Stopping server...');
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
// Windows: use taskkill with /t to kill entire process tree
|
try {
|
||||||
// This prevents orphaned node processes when closing the app
|
// Windows: use taskkill with /t to kill entire process tree
|
||||||
spawn('taskkill', ['/f', '/t', '/pid', serverProcess.pid.toString()]);
|
// 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 {
|
} else {
|
||||||
serverProcess.kill('SIGTERM');
|
serverProcess.kill('SIGTERM');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user