fix(onboard): clamp gateway reachability polling · openclaw/openclaw@bb680a8
steipete
·
2026-05-31
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -16,6 +16,7 @@ import {
|
16 | 16 | resolveControlUiLinks, |
17 | 17 | summarizeExistingConfig, |
18 | 18 | validateGatewayPasswordInput, |
| 19 | +waitForGatewayReachable, |
19 | 20 | } from "./onboard-helpers.js"; |
20 | 21 | |
21 | 22 | const mocks = vi.hoisted(() => ({ |
@@ -307,6 +308,31 @@ describe("probeGatewayReachable", () => {
|
307 | 308 | }); |
308 | 309 | }); |
309 | 310 | |
| 311 | +describe("waitForGatewayReachable", () => { |
| 312 | +it("keeps oversized poll intervals within the overall deadline", async () => { |
| 313 | +mocks.probeGateway.mockResolvedValue({ |
| 314 | +ok: false, |
| 315 | +url: "ws://127.0.0.1:18789", |
| 316 | +connectLatencyMs: null, |
| 317 | +error: "connect failed: timeout", |
| 318 | +close: null, |
| 319 | +health: null, |
| 320 | +status: null, |
| 321 | +presence: null, |
| 322 | +configSnapshot: null, |
| 323 | +}); |
| 324 | + |
| 325 | +const result = await waitForGatewayReachable({ |
| 326 | +url: "ws://127.0.0.1:18789", |
| 327 | +deadlineMs: 5, |
| 328 | +pollMs: Number.MAX_SAFE_INTEGER, |
| 329 | +probeTimeoutMs: 1, |
| 330 | +}); |
| 331 | + |
| 332 | +expect(result).toEqual({ ok: false, detail: "connect failed: timeout" }); |
| 333 | +}); |
| 334 | +}); |
| 335 | + |
310 | 336 | describe("summarizeExistingConfig", () => { |
311 | 337 | it("collapses gateway fields into a friendly remote summary", () => { |
312 | 338 | expect( |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
2 | 2 | import path from "node:path"; |
3 | 3 | import { inspect } from "node:util"; |
4 | 4 | import { cancel, isCancel } from "@clack/prompts"; |
| 5 | +import { resolveTimerTimeoutMs } from "@openclaw/normalization-core/number-coercion"; |
5 | 6 | import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; |
6 | 7 | import { uniqueStrings } from "@openclaw/normalization-core/string-normalization"; |
7 | 8 | import { visibleWidth } from "../../packages/terminal-core/src/ansi.js"; |
@@ -339,7 +340,7 @@ export async function waitForGatewayReachable(params: {
|
339 | 340 | pollMs?: number; |
340 | 341 | }): Promise<{ ok: boolean; detail?: string }> { |
341 | 342 | const deadlineMs = params.deadlineMs ?? 15_000; |
342 | | -const pollMs = params.pollMs ?? 400; |
| 343 | +const pollMs = resolveTimerTimeoutMs(params.pollMs ?? 400, 400, 0); |
343 | 344 | const probeTimeoutMs = params.probeTimeoutMs ?? 1500; |
344 | 345 | const startedAt = Date.now(); |
345 | 346 | let lastDetail: string | undefined; |
@@ -355,7 +356,11 @@ export async function waitForGatewayReachable(params: {
|
355 | 356 | return probe; |
356 | 357 | } |
357 | 358 | lastDetail = probe.detail; |
358 | | -await sleep(pollMs); |
| 359 | +const remainingMs = deadlineMs - (Date.now() - startedAt); |
| 360 | +if (remainingMs <= 0) { |
| 361 | +break; |
| 362 | +} |
| 363 | +await sleep(Math.min(pollMs, remainingMs)); |
359 | 364 | } |
360 | 365 | |
361 | 366 | return { ok: false, detail: lastDetail }; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。