mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
fix(tlon): clamp sse reconnect delays
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user