Ver código fonte

fix(subprocess): order runner stdio shutdown

pku-xht 1 mês atrás
pai
commit
889cbd45f1

+ 6 - 6
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<void> {