diff --git a/src/shared/pid-alive.test.ts b/src/shared/pid-alive.test.ts index 6f1cde0634eb..9f744f71f5a2 100644 --- a/src/shared/pid-alive.test.ts +++ b/src/shared/pid-alive.test.ts @@ -165,14 +165,18 @@ describe("process start times", () => { expect.objectContaining({ encoding: "utf8", env: expect.objectContaining({ LC_ALL: "C", TZ: "UTC" }), + timeout: 1000, }), ); }); }); - it("returns null for unavailable Darwin file-lock start times", () => { + it("fails conservatively when the Darwin file-lock start-time probe times out", () => { vi.spyOn(childProcess, "execFileSync").mockImplementation(() => { - throw new Error("missing process"); + throw Object.assign(new Error("spawnSync /bin/ps ETIMEDOUT"), { + code: "ETIMEDOUT", + signal: "SIGTERM", + }); }); return withMockedPlatform("darwin", async () => { diff --git a/src/shared/pid-alive.ts b/src/shared/pid-alive.ts index 60fc26187150..b36955e25dfc 100644 --- a/src/shared/pid-alive.ts +++ b/src/shared/pid-alive.ts @@ -2,6 +2,8 @@ import childProcess from "node:child_process"; import fsSync from "node:fs"; +const DARWIN_PS_TIMEOUT_MS = 1000; + function isValidPid(pid: number): boolean { return Number.isInteger(pid) && pid > 0; } @@ -59,6 +61,7 @@ function getDarwinProcessStartTime(pid: number): number | null { encoding: "utf8", env: { ...process.env, LC_ALL: "C", TZ: "UTC" }, stdio: ["ignore", "pipe", "ignore"], + timeout: DARWIN_PS_TIMEOUT_MS, }) .trim(); // Darwin's lstart output has no timezone. Force UTC for both ps and parsing so