fix(scripts): clamp openwebui probe timer · openclaw/openclaw@45a93b8
vincentkoc
·
2026-06-22
·
via Recent Commits to openclaw:main
File tree
scripts/e2e/lib/openwebui
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2,13 +2,20 @@
|
2 | 2 | import { pathToFileURL } from "node:url"; |
3 | 3 | import { readPositiveIntEnv } from "../env-limits.mjs"; |
4 | 4 | |
| 5 | +const MAX_TIMER_TIMEOUT_MS = 2_147_000_000; |
| 6 | + |
5 | 7 | function parseExpectedStatus(raw) { |
6 | 8 | if (!/^[1-5]\d\d$/u.test(raw)) { |
7 | 9 | throw new Error(`expected status must be lt500 or a decimal HTTP status. Got: ${raw}`); |
8 | 10 | } |
9 | 11 | return Number(raw); |
10 | 12 | } |
11 | 13 | |
| 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 | + |
12 | 19 | export async function probeHttpStatus({ |
13 | 20 | url, |
14 | 21 | expectedRaw = "200", |
@@ -20,8 +27,9 @@ export async function probeHttpStatus({
|
20 | 27 | throw new Error("usage: http-probe.mjs <url> [status|lt500]"); |
21 | 28 | } |
22 | 29 | const expectedStatus = expectedRaw === "lt500" ? undefined : parseExpectedStatus(expectedRaw); |
| 30 | +const resolvedTimeoutMs = resolveTimerTimeoutMs(timeoutMs, 30_000); |
23 | 31 | const controller = new AbortController(); |
24 | | -const timer = setTimeout(() => controller.abort(), timeoutMs); |
| 32 | +const timer = setTimeout(() => controller.abort(), resolvedTimeoutMs); |
25 | 33 | let res; |
26 | 34 | const headers = {}; |
27 | 35 | if (bearer) { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -4,6 +4,7 @@ import fs from "node:fs";
|
4 | 4 | import { createServer, type Server } from "node:http"; |
5 | 5 | import os from "node:os"; |
6 | 6 | import path from "node:path"; |
| 7 | +import { MAX_TIMER_TIMEOUT_MS } from "@openclaw/normalization-core/number-coercion"; |
7 | 8 | import { describe, expect, it } from "vitest"; |
8 | 9 | import { createBoundedChildOutput } from "../helpers/bounded-child-output.js"; |
9 | 10 | |
@@ -236,4 +237,30 @@ describe("e2e helper numeric env limits", () => {
|
236 | 237 | ).resolves.toBe(true); |
237 | 238 | expect(canceled).toBe(true); |
238 | 239 | }); |
| 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 | +}); |
239 | 266 | }); |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。