From 2d0f0d0ec0e8a348529fa6f0954d0fe06db51630 Mon Sep 17 00:00:00 2001 From: Alix-007 Date: Fri, 17 Jul 2026 00:00:06 +0800 Subject: [PATCH] fix(daemon): bound Node runtime probes (#109127) --- src/daemon/runtime-paths.test.ts | 4 ++-- src/daemon/runtime-paths.ts | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/daemon/runtime-paths.test.ts b/src/daemon/runtime-paths.test.ts index 3cbdbdca3885..4e6abfed4018 100644 --- a/src/daemon/runtime-paths.test.ts +++ b/src/daemon/runtime-paths.test.ts @@ -219,7 +219,7 @@ describe("resolvePreferredNodePath", () => { expect(execFile).toHaveBeenCalledWith( darwinNode, ["-e", expect.stringContaining("SELECT sqlite_version() AS version")], - { encoding: "utf8" }, + { encoding: "utf8", timeoutMs: 5_000 }, ); }); @@ -462,7 +462,7 @@ describe("resolveSystemNodeInfo", () => { expect(execFile).toHaveBeenCalledWith( homebrewOptNode, ["-e", expect.stringContaining("SELECT sqlite_version() AS version")], - { encoding: "utf8" }, + { encoding: "utf8", timeoutMs: 5_000 }, ); }); diff --git a/src/daemon/runtime-paths.ts b/src/daemon/runtime-paths.ts index f2df0e736797..bb5a90a95eae 100644 --- a/src/daemon/runtime-paths.ts +++ b/src/daemon/runtime-paths.ts @@ -75,11 +75,13 @@ function buildSystemNodeCandidates( type ExecFileAsync = ( file: string, args: readonly string[], - options: { encoding: "utf8" }, + options: { encoding: "utf8"; timeoutMs: number }, ) => Promise<{ stdout: string; stderr: string }>; -const execFileAsync: ExecFileAsync = async (file, args) => - await runExec(file, [...args], { logOutput: false }); +const NODE_RUNTIME_PROBE_TIMEOUT_MS = 5_000; + +const execFileAsync: ExecFileAsync = async (file, args, options) => + await runExec(file, [...args], { logOutput: false, timeoutMs: options.timeoutMs }); const NODE_RUNTIME_PROBE = String.raw` let sqliteVersion = null; @@ -108,6 +110,7 @@ async function resolveNodeRuntimeInfo( try { const { stdout } = await execFileImpl(nodePath, ["-e", NODE_RUNTIME_PROBE], { encoding: "utf8", + timeoutMs: NODE_RUNTIME_PROBE_TIMEOUT_MS, }); const parsed = JSON.parse(stdout) as { nodeVersion?: unknown;