Skip to content

Commit 03a9fab

Browse files
fix(cli): first render on Windows no longer fails while a new browser or ffmpeg is scanned (#5625)
1 parent f35b05f commit 03a9fab

5 files changed

Lines changed: 35 additions & 22 deletions

File tree

‎packages/cli/src/browser/ffmpeg.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function detectH264EncoderMode(ffmpegPath: string, gpuRequested: boolean)
3535
const encoders = execFileSync(ffmpegPath, ["-hide_banner", "-encoders"], {
3636
encoding: "utf-8",
3737
stdio: ["ignore", "pipe", "pipe"],
38-
timeout: 5000,
38+
timeout: FIRST_LAUNCH_TIMEOUT_MS,
3939
windowsHide: true,
4040
});
4141
return resolveH264EncoderMode(encoders, gpuRequested);
@@ -48,7 +48,7 @@ export async function detectH264EncoderModeForRender(
4848
): Promise<H264EncoderMode> {
4949
const result = await runCancellableProcess(ffmpegPath, ["-hide_banner", "-encoders"], {
5050
signal,
51-
timeoutMs: 5000,
51+
timeoutMs: FIRST_LAUNCH_TIMEOUT_MS,
5252
});
5353
return resolveH264EncoderMode(result.stdout, gpuRequested);
5454
}
@@ -64,6 +64,7 @@ export function findFFprobe(): string | undefined {
6464
return findFfBinary("ffprobe", { configuredMustExist: true });
6565
}
6666

67+
export const FIRST_LAUNCH_TIMEOUT_MS = 60_000;
6768
const FFMPEG_DOWNLOAD_URL = "https://ffmpeg.org/download.html";
6869

6970
/**

‎packages/cli/src/browser/preflight.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe("runEnvironmentChecks", () => {
6060
expect(runProcess).toHaveBeenCalledWith(
6161
process.execPath,
6262
["-version"],
63-
expect.objectContaining({ timeoutMs: 5000 }),
63+
expect.objectContaining({ timeoutMs: 60_000 }),
6464
);
6565
});
6666

@@ -258,7 +258,7 @@ describe("runEnvironmentChecks", () => {
258258
process.execPath,
259259
["--version"],
260260
expect.objectContaining({
261-
timeoutMs: 5000,
261+
timeoutMs: 60_000,
262262
maxBufferBytes: 64 * 1024,
263263
}),
264264
);

‎packages/cli/src/browser/preflight.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import { platform } from "node:os";
33
import { findFfBinary } from "@hyperframes/parsers/ff-binaries";
44
import { ensureBrowser, findBrowser, type BrowserResult } from "./manager.js";
55
import { describeBrowserInstall, type BrowserInstallFacts } from "./installFacts.js";
6-
import { FFMPEG_PATH_ENV, FFPROBE_PATH_ENV, getFFmpegInstallHint } from "./ffmpeg.js";
6+
import {
7+
FFMPEG_PATH_ENV,
8+
FFPROBE_PATH_ENV,
9+
FIRST_LAUNCH_TIMEOUT_MS,
10+
getFFmpegInstallHint,
11+
} from "./ffmpeg.js";
712
import {
813
chromeDepsInstallCommand,
914
detectLinuxDistro,
@@ -78,7 +83,7 @@ async function readToolVersion(
7883
const output = (
7984
await runCancellableProcess(binaryPath, ["-version"], {
8085
signal,
81-
timeoutMs: 5000,
86+
timeoutMs: FIRST_LAUNCH_TIMEOUT_MS,
8287
})
8388
).stdout;
8489
const raw = output.split("\n")[0] ?? "";
@@ -260,7 +265,7 @@ async function chromeLaunchOutcome(
260265
try {
261266
const { stdout } = await runCancellableProcess(executablePath, ["--version"], {
262267
signal,
263-
timeoutMs: 5000,
268+
timeoutMs: FIRST_LAUNCH_TIMEOUT_MS,
264269
maxBufferBytes: 64 * 1024,
265270
});
266271
return { ...found, versionMajor: extractMajorVersion(stdout) };
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { describe, expect, it, vi } from "vitest";
2+
3+
vi.mock("./processTree.js", () => ({
4+
terminateProcessTree: () => Promise.reject(new Error("taskkill exited with status 128")),
5+
}));
6+
7+
const { runCancellableProcess } = await import("./cancellableProcess.js");
8+
9+
describe("runCancellableProcess when the tree kill fails", () => {
10+
it("still rejects with the timeout, not the kill failure", async () => {
11+
const run = runCancellableProcess(process.execPath, ["-e", "setTimeout(() => {}, 400)"], {
12+
timeoutMs: 50,
13+
});
14+
15+
await expect(run).rejects.toMatchObject({
16+
message: "Process timed out after 50 ms",
17+
code: "ETIMEDOUT",
18+
});
19+
});
20+
});

‎packages/cli/src/utils/cancellableProcess.ts‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,7 @@ export function runCancellableProcess(
9090
};
9191
const finishReject = async (error: unknown): Promise<void> => {
9292
if (settled) return;
93-
if (terminationTask) {
94-
try {
95-
terminationSignal = await terminationTask;
96-
} catch (terminationError) {
97-
error = terminationError;
98-
}
99-
}
93+
if (terminationTask) terminationSignal = await terminationTask.catch(() => terminationSignal);
10094
if (settled) return;
10195
settled = true;
10296
cleanup();
@@ -130,14 +124,7 @@ export function runCancellableProcess(
130124
// fallow-ignore-next-line complexity
131125
child.once("close", async (status, closeSignal) => {
132126
if (settled) return;
133-
if (terminationTask) {
134-
try {
135-
terminationSignal = await terminationTask;
136-
} catch (error) {
137-
await finishReject(error);
138-
return;
139-
}
140-
}
127+
if (terminationTask) terminationSignal = await terminationTask.catch(() => terminationSignal);
141128
if (settled) return;
142129
settled = true;
143130
cleanup();

0 commit comments

Comments
 (0)