mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 22:32:52 +00:00
fix(feishu): clamp sequential queue timeouts
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { createSequentialQueue } from "./sequential-queue.js";
|
||||
|
||||
@@ -132,6 +133,25 @@ describe("createSequentialQueue", () => {
|
||||
await stuck;
|
||||
});
|
||||
|
||||
it("clamps oversized task timeouts before scheduling", async () => {
|
||||
vi.useFakeTimers();
|
||||
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
|
||||
const enqueue = createSequentialQueue({
|
||||
taskTimeoutMs: Number.MAX_SAFE_INTEGER,
|
||||
});
|
||||
const gate = createDeferred();
|
||||
|
||||
const first = enqueue("feishu:default:chat-large-timeout", async () => {
|
||||
await gate.promise;
|
||||
});
|
||||
|
||||
await Promise.resolve();
|
||||
expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS);
|
||||
|
||||
gate.resolve();
|
||||
await first;
|
||||
});
|
||||
|
||||
it("disables the timeout cap when taskTimeoutMs is 0 (legacy behavior)", async () => {
|
||||
vi.useFakeTimers();
|
||||
const timeouts: Array<{ key: string; timeoutMs: number }> = [];
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { resolveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime";
|
||||
|
||||
/**
|
||||
* Per-key serial task queue for Feishu inbound message handling.
|
||||
*
|
||||
@@ -65,16 +67,17 @@ async function boundedRun(
|
||||
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
||||
return task();
|
||||
}
|
||||
const resolvedTimeoutMs = resolveTimerTimeoutMs(timeoutMs, DEFAULT_TASK_TIMEOUT_MS);
|
||||
let timeoutHandle: ReturnType<typeof setTimeout> | undefined;
|
||||
const timeoutPromise = new Promise<void>((resolve) => {
|
||||
timeoutHandle = setTimeout(() => {
|
||||
try {
|
||||
onTaskTimeout?.(key, timeoutMs);
|
||||
onTaskTimeout?.(key, resolvedTimeoutMs);
|
||||
} catch {
|
||||
// Swallow logging errors so they cannot poison the queue chain.
|
||||
}
|
||||
resolve();
|
||||
}, timeoutMs);
|
||||
}, resolvedTimeoutMs);
|
||||
});
|
||||
try {
|
||||
await Promise.race([task(), timeoutPromise]);
|
||||
|
||||
Reference in New Issue
Block a user