mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-24 16:02:55 +08:00
fix(cli): race pipe drains against timeout so tsc hangs are killed
This commit is contained in:
@@ -33,17 +33,21 @@ export namespace TsCheck {
|
||||
})
|
||||
|
||||
const TIMEOUT = 30_000
|
||||
const stdout = await new Response(proc.stdout).text()
|
||||
const stderr = await new Response(proc.stderr).text()
|
||||
const exited = await Promise.race([
|
||||
proc.exited.then(() => true),
|
||||
new Promise<false>((r) => setTimeout(() => r(false), TIMEOUT)),
|
||||
const done = Promise.all([new Response(proc.stdout).text(), new Response(proc.stderr).text(), proc.exited])
|
||||
const settled = await Promise.race([
|
||||
done.then(([out, err]) => ({ out, err, timedOut: false as const })),
|
||||
new Promise<{ out: string; err: string; timedOut: true }>((r) =>
|
||||
setTimeout(() => r({ out: "", err: "", timedOut: true }), TIMEOUT),
|
||||
),
|
||||
])
|
||||
if (!exited) {
|
||||
if (settled.timedOut) {
|
||||
log.warn("ts check timed out, killing process", { elapsed: Date.now() - start })
|
||||
proc.kill()
|
||||
}
|
||||
|
||||
const stdout = settled.out
|
||||
const stderr = settled.err
|
||||
|
||||
log.info("ts check done", {
|
||||
elapsed: Date.now() - start,
|
||||
lines: stdout.split("\n").length,
|
||||
|
||||
Reference in New Issue
Block a user