Skip to content

Commit 45a93b8

Browse files
committed
fix(scripts): clamp openwebui probe timer
1 parent a267575 commit 45a93b8

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

scripts/e2e/lib/openwebui/http-probe.mjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
import { pathToFileURL } from "node:url";
33
import { readPositiveIntEnv } from "../env-limits.mjs";
44

5+
const MAX_TIMER_TIMEOUT_MS = 2_147_000_000;
6+
57
function parseExpectedStatus(raw) {
68
if (!/^[1-5]\d\d$/u.test(raw)) {
79
throw new Error(`expected status must be lt500 or a decimal HTTP status. Got: ${raw}`);
810
}
911
return Number(raw);
1012
}
1113

14+
function resolveTimerTimeoutMs(valueMs, fallbackMs) {
15+
const value = Number.isFinite(valueMs) ? valueMs : fallbackMs;
16+
return Math.min(Math.max(Math.floor(value), 1), MAX_TIMER_TIMEOUT_MS);
17+
}
18+
1219
export async function probeHttpStatus({
1320
url,
1421
expectedRaw = "200",
@@ -20,8 +27,9 @@ export async function probeHttpStatus({
2027
throw new Error("usage: http-probe.mjs <url> [status|lt500]");
2128
}
2229
const expectedStatus = expectedRaw === "lt500" ? undefined : parseExpectedStatus(expectedRaw);
30+
const resolvedTimeoutMs = resolveTimerTimeoutMs(timeoutMs, 30_000);
2331
const controller = new AbortController();
24-
const timer = setTimeout(() => controller.abort(), timeoutMs);
32+
const timer = setTimeout(() => controller.abort(), resolvedTimeoutMs);
2533
let res;
2634
const headers = {};
2735
if (bearer) {

test/scripts/e2e-helper-env-limits.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import fs from "node:fs";
44
import { createServer, type Server } from "node:http";
55
import os from "node:os";
66
import path from "node:path";
7+
import { MAX_TIMER_TIMEOUT_MS } from "@openclaw/normalization-core/number-coercion";
78
import { describe, expect, it } from "vitest";
89
import { createBoundedChildOutput } from "../helpers/bounded-child-output.js";
910

@@ -236,4 +237,30 @@ describe("e2e helper numeric env limits", () => {
236237
).resolves.toBe(true);
237238
expect(canceled).toBe(true);
238239
});
240+
241+
it("clamps oversized Open WebUI HTTP probe timers before scheduling", async () => {
242+
const { probeHttpStatus } = await import("../../scripts/e2e/lib/openwebui/http-probe.mjs");
243+
const fetchImpl = (async (_url: string, init: RequestInit) => {
244+
await new Promise<void>((resolve, reject) => {
245+
const timer = setTimeout(resolve, 25);
246+
init.signal?.addEventListener(
247+
"abort",
248+
() => {
249+
clearTimeout(timer);
250+
reject(new Error("aborted"));
251+
},
252+
{ once: true },
253+
);
254+
});
255+
return new Response(null, { status: 200 });
256+
}) as typeof fetch;
257+
258+
await expect(
259+
probeHttpStatus({
260+
fetchImpl,
261+
timeoutMs: MAX_TIMER_TIMEOUT_MS + 1,
262+
url: "http://127.0.0.1/probe",
263+
}),
264+
).resolves.toBe(true);
265+
});
239266
});

0 commit comments

Comments
 (0)