fix: kill process tree on Windows via taskkill before SIGTERM fallback
On Windows, child.kill('SIGTERM') only terminates the cmd.exe wrapper,
leaving the inner opencode.exe serve running as an orphan. This adds
killProcessTree() which runs taskkill /PID /T /F first, then falls
back to child.kill('SIGTERM') for the close() method.
Fixes #1889
This commit is contained in:
@@ -133,6 +133,19 @@ function shouldUseWindowsShell(binary: string): boolean {
|
||||
return !ext && !trimmed.includes('\\') && !trimmed.includes('/');
|
||||
}
|
||||
|
||||
function killProcessTree(pid: number | undefined): void {
|
||||
if (!Number.isInteger(pid)) return;
|
||||
if (process.platform === 'win32') {
|
||||
try {
|
||||
spawnSync('taskkill', ['/PID', String(pid), '/T', '/F'], {
|
||||
stdio: 'ignore', timeout: 5000, windowsHide: true,
|
||||
});
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function appendToPath(dir: string) {
|
||||
const trimmed = (dir || '').trim();
|
||||
if (!trimmed) return;
|
||||
@@ -695,6 +708,7 @@ async function spawnManagedOpenCodeServer(
|
||||
return {
|
||||
url,
|
||||
close: () => {
|
||||
killProcessTree(child.pid);
|
||||
try {
|
||||
child.kill('SIGTERM');
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user