From 40d150be5ebbee8bf2c01c9d863e51ef43e2d53a Mon Sep 17 00:00:00 2001 From: Ani Betts Date: Fri, 24 Jan 2025 03:56:24 +0100 Subject: [PATCH] node: Fix race condition with accessing stdioOptions (#16670) --- src/js/node/child_process.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/js/node/child_process.ts b/src/js/node/child_process.ts index 5849277850..2a719ba727 100644 --- a/src/js/node/child_process.ts +++ b/src/js/node/child_process.ts @@ -1275,12 +1275,16 @@ class ChildProcess extends EventEmitter { env: env, detached: typeof detachedOption !== "undefined" ? !!detachedOption : false, onExit: (handle, exitCode, signalCode, err) => { - if (hasSocketsToEagerlyLoad) { - this.stdio; - } - $debug("ChildProcess: onExit", exitCode, signalCode, err, this.pid); this.#handle = handle; this.pid = this.#handle.pid; + $debug("ChildProcess: onExit", exitCode, signalCode, err, this.pid); + + if (hasSocketsToEagerlyLoad) { + process.nextTick(() => { + this.stdio; + $debug("ChildProcess: onExit", exitCode, signalCode, err, this.pid); + }); + } process.nextTick( (exitCode, signalCode, err) => this.#handleOnExit(exitCode, signalCode, err),