fix(browser): cap cli request timeouts · openclaw/openclaw@b073094
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
File tree
extensions/browser/src/cli
| Original file line number | Diff line number | Diff line change |
|---|
@@ -38,4 +38,31 @@ describe("callBrowserRequest", () => {
|
38 | 38 | ).rejects.toThrow("--timeout must be a positive integer."); |
39 | 39 | expect(gatewayMocks.callGatewayFromCli).not.toHaveBeenCalled(); |
40 | 40 | }); |
| 41 | + |
| 42 | +it("caps explicit request timeouts to Node's safe timer range", async () => { |
| 43 | +await callBrowserRequest( |
| 44 | +{ json: true }, |
| 45 | +{ method: "GET", path: "/status" }, |
| 46 | +{ timeoutMs: 3_000_000_000 }, |
| 47 | +); |
| 48 | + |
| 49 | +const call = gatewayMocks.callGatewayFromCli.mock.calls[0] as unknown as |
| 50 | +| CallGatewayFromCliArgs |
| 51 | +| undefined; |
| 52 | +expect(call?.[1]).toMatchObject({ timeout: "2147483647" }); |
| 53 | +expect(call?.[2]).toMatchObject({ timeoutMs: 2_147_483_647 }); |
| 54 | +}); |
| 55 | + |
| 56 | +it("caps parent timeout values to Node's safe timer range", async () => { |
| 57 | +await callBrowserRequest( |
| 58 | +{ json: true, timeout: "3000000000" }, |
| 59 | +{ method: "GET", path: "/status" }, |
| 60 | +); |
| 61 | + |
| 62 | +const call = gatewayMocks.callGatewayFromCli.mock.calls[0] as unknown as |
| 63 | +| CallGatewayFromCliArgs |
| 64 | +| undefined; |
| 65 | +expect(call?.[1]).toMatchObject({ timeout: "2147483647" }); |
| 66 | +expect(call?.[2]).toMatchObject({ timeoutMs: 2_147_483_647 }); |
| 67 | +}); |
41 | 68 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,8 @@ import {
|
5 | 5 | } from "../browser-gateway-contract.js"; |
6 | 6 | import { callGatewayFromCli, type GatewayRpcOpts } from "./core-api.js"; |
7 | 7 | |
| 8 | +const MAX_SAFE_TIMEOUT_DELAY_MS = 2_147_483_647; |
| 9 | + |
8 | 10 | export type BrowserParentOpts = GatewayRpcOpts & { |
9 | 11 | json?: boolean; |
10 | 12 | browserProfile?: string; |
@@ -43,16 +45,20 @@ function parsePositiveInteger(raw: string, flag: string): number {
|
43 | 45 | return parsed; |
44 | 46 | } |
45 | 47 | |
| 48 | +function normalizeCliTimeoutMs(timeoutMs: number): number { |
| 49 | +return Math.min(MAX_SAFE_TIMEOUT_DELAY_MS, Math.max(1, Math.floor(timeoutMs))); |
| 50 | +} |
| 51 | + |
46 | 52 | export async function callBrowserRequest<T>( |
47 | 53 | opts: BrowserParentOpts, |
48 | 54 | params: BrowserRequestParams, |
49 | 55 | extra?: { timeoutMs?: number; progress?: boolean }, |
50 | 56 | ): Promise<T> { |
51 | 57 | const resolvedTimeoutMs = |
52 | 58 | typeof extra?.timeoutMs === "number" && Number.isFinite(extra.timeoutMs) |
53 | | - ? Math.max(1, Math.floor(extra.timeoutMs)) |
| 59 | + ? normalizeCliTimeoutMs(extra.timeoutMs) |
54 | 60 | : typeof opts.timeout === "string" |
55 | | - ? parsePositiveInteger(opts.timeout, "--timeout") |
| 61 | + ? normalizeCliTimeoutMs(parsePositiveInteger(opts.timeout, "--timeout")) |
56 | 62 | : undefined; |
57 | 63 | const resolvedTimeout = |
58 | 64 | typeof resolvedTimeoutMs === "number" && Number.isFinite(resolvedTimeoutMs) |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。