mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-08 11:02:26 +00:00
fix(gateway-client): clamp tick watchdog intervals
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user