fix(gateway-client): clamp tick watchdog intervals

This commit is contained in:
Peter Steinberger
2026-05-30 18:29:37 -04:00
parent 59f96078b2
commit 984951f55c
2 changed files with 34 additions and 1 deletions

View File

@@ -1389,7 +1389,7 @@ export class GatewayClient {
typeof rawMinInterval === "number" && Number.isFinite(rawMinInterval)
? Math.max(1, Math.min(30_000, rawMinInterval))
: 1000;
const interval = Math.max(this.tickIntervalMs, minInterval);
const interval = resolveSafeTimeoutDelayMs(Math.max(this.tickIntervalMs, minInterval));
this.tickTimer = setInterval(() => {
if (this.closed) {
return;

View File

@@ -253,6 +253,39 @@ describe("GatewayClient", () => {
}
});
test("clamps oversized tick watchdog intervals before scheduling", () => {
vi.useFakeTimers();
try {
const setIntervalSpy = vi.spyOn(globalThis, "setInterval");
const client = new GatewayClient({
tickWatchMinIntervalMs: 5,
});
Object.assign(
client as unknown as { ws: unknown; tickIntervalMs: number; lastTick: number },
{
ws: {
readyState: WebSocket.OPEN,
send: vi.fn(),
close: vi.fn(),
},
tickIntervalMs: Number.MAX_SAFE_INTEGER,
lastTick: Date.now(),
},
);
(
client as unknown as {
startTickWatch: () => void;
}
).startTickWatch();
expect(setIntervalSpy).toHaveBeenCalledWith(expect.any(Function), MAX_SAFE_TIMEOUT_DELAY_MS);
client.stop();
} finally {
vi.useRealTimers();
}
});
test("times out unresolved requests and clears pending state", async () => {
vi.useFakeTimers();
try {