From 889cbd45f1c4da1114366a4d793d15db2f11f324 Mon Sep 17 00:00:00 2001 From: pku-xht Date: Fri, 21 Aug 2026 07:49:15 +0800 Subject: [PATCH] fix(subprocess): order runner stdio shutdown --- .../subprocess/subprocess-local/src/spawn-runner.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/subprocess/subprocess-local/src/spawn-runner.ts b/packages/subprocess/subprocess-local/src/spawn-runner.ts index 4b8c6da4b8..45bfac7ffa 100644 --- a/packages/subprocess/subprocess-local/src/spawn-runner.ts +++ b/packages/subprocess/subprocess-local/src/spawn-runner.ts @@ -102,6 +102,12 @@ function releaseRunnerStdio(): void { const stdin = process.stdin const stdout = process.stdout const stderr = process.stderr + // A loader may already have materialized Node's libuv stdio wrappers. Their + // shutdown must be requested before the CRT descriptors close; the target + // keeps the handles CreateProcessW inherited and remains the only pipe writer. + stdin.destroy() + stdout.end() + stderr.end() for (const fd of [0, 1, 2]) { try { closeSync(fd) @@ -109,12 +115,6 @@ function releaseRunnerStdio(): void { if ((error as NodeJS.ErrnoException).code !== 'EBADF') throw error } } - // A loader may already have materialized Node's libuv stdio wrappers. Settle - // those runner-owned references after closing the CRT descriptors; the target - // keeps the handles CreateProcessW inherited and remains the only pipe writer. - stdin.destroy() - stdout.end() - stderr.end() } async function runWin32(request: RunnerRequest, eventsPath: string): Promise {