fix(feishu): clamp abortable delay timers

This commit is contained in:
Peter Steinberger
2026-05-30 17:12:08 -04:00
parent 1f92a3e351
commit ed59533574
2 changed files with 16 additions and 1 deletions

View File

@@ -49,4 +49,19 @@ describe("waitForAbortableDelay", () => {
await expect(delay).resolves.toBe(true);
});
it("normalizes oversized delays before arming the timer", async () => {
const timeoutSpy = vi
.spyOn(globalThis, "setTimeout")
.mockImplementation((callback: () => void) => {
queueMicrotask(callback);
return 1 as unknown as ReturnType<typeof setTimeout>;
});
vi.spyOn(globalThis, "clearTimeout").mockImplementation(() => undefined);
const delay = waitForAbortableDelay(Number.MAX_SAFE_INTEGER);
expect(timeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS);
await expect(delay).resolves.toBe(true);
});
});

View File

@@ -101,7 +101,7 @@ export function waitForAbortableDelay(
return;
}
timer = setTimeout(() => finish(true), delayMs);
timer = setTimeout(() => finish(true), resolveTimerTimeoutMs(delayMs, 1));
timer.unref?.();
});
}