fix(coding-agent): fix windows hanging when descendants inherit stdout/stderr handles (#2389)

This commit is contained in:
Duncan Ogilvie
2026-03-19 08:34:52 +01:00
committed by GitHub
parent ff1ea12324
commit 25b185f398
5 changed files with 247 additions and 36 deletions

View File

@@ -3,6 +3,7 @@
*/
import { spawn } from "node:child_process";
import { waitForChildProcess } from "../utils/child-process.js";
/**
* Options for executing shell commands.
@@ -85,20 +86,22 @@ export async function execCommand(
stderr += data.toString();
});
proc.on("close", (code) => {
if (timeoutId) clearTimeout(timeoutId);
if (options?.signal) {
options.signal.removeEventListener("abort", killProcess);
}
resolve({ stdout, stderr, code: code ?? 0, killed });
});
proc.on("error", (_err) => {
if (timeoutId) clearTimeout(timeoutId);
if (options?.signal) {
options.signal.removeEventListener("abort", killProcess);
}
resolve({ stdout, stderr, code: 1, killed });
});
// Wait for process termination without hanging on inherited stdio handles
// held open by detached descendants.
waitForChildProcess(proc)
.then((code) => {
if (timeoutId) clearTimeout(timeoutId);
if (options?.signal) {
options.signal.removeEventListener("abort", killProcess);
}
resolve({ stdout, stderr, code: code ?? 0, killed });
})
.catch((_err) => {
if (timeoutId) clearTimeout(timeoutId);
if (options?.signal) {
options.signal.removeEventListener("abort", killProcess);
}
resolve({ stdout, stderr, code: 1, killed });
});
});
}