fix(tlon): clamp sse reconnect delays

This commit is contained in:
Peter Steinberger
2026-05-30 16:58:38 -04:00
parent 87eae7f811
commit 65167c9637
2 changed files with 14 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { urbitFetch } from "./fetch.js";
import { UrbitSSEClient } from "./sse-client.js";
@@ -137,6 +138,16 @@ describe("UrbitSSEClient", () => {
expect(client.onReconnect).toBe(onReconnect);
});
it("clamps oversized reconnect delays", () => {
const client = new UrbitSSEClient("https://example.com", "urbauth-~zod=123", {
reconnectDelay: Number.MAX_SAFE_INTEGER,
maxReconnectDelay: Number.MAX_SAFE_INTEGER,
});
expect(client.reconnectDelay).toBe(MAX_TIMER_TIMEOUT_MS);
expect(client.maxReconnectDelay).toBe(MAX_TIMER_TIMEOUT_MS);
});
it("resets reconnect attempts on successful connect", async () => {
const mockUrbitFetch = vi.mocked(urbitFetch);

View File

@@ -1,5 +1,6 @@
import { randomUUID } from "node:crypto";
import { Readable } from "node:stream";
import { resolveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime";
import type { LookupFn, SsrFPolicy } from "openclaw/plugin-sdk/ssrf-runtime";
import { ensureUrbitChannelOpen, pokeUrbitChannel, scryUrbitPath } from "./channel-ops.js";
import { getUrbitContext, normalizeUrbitCookie } from "./context.js";
@@ -87,8 +88,8 @@ export class UrbitSSEClient {
this.onReconnect = options.onReconnect ?? null;
this.autoReconnect = options.autoReconnect !== false;
this.maxReconnectAttempts = options.maxReconnectAttempts ?? 10;
this.reconnectDelay = options.reconnectDelay ?? 1000;
this.maxReconnectDelay = options.maxReconnectDelay ?? 30000;
this.reconnectDelay = resolveTimerTimeoutMs(options.reconnectDelay, 1000);
this.maxReconnectDelay = resolveTimerTimeoutMs(options.maxReconnectDelay, 30000);
this.logger = options.logger ?? {};
this.ssrfPolicy = options.ssrfPolicy;
this.lookupFn = options.lookupFn;