mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-08 11:02:26 +00:00
fix(gateway): clean pending request when send fails
This commit is contained in:
@@ -1599,7 +1599,14 @@ export class GatewayClient {
|
||||
});
|
||||
signal?.addEventListener("abort", abortHandler, { once: true });
|
||||
});
|
||||
this.ws.send(JSON.stringify(frame));
|
||||
try {
|
||||
this.ws.send(JSON.stringify(frame));
|
||||
} catch (error) {
|
||||
const pending = this.pending.get(id);
|
||||
this.pending.delete(id);
|
||||
pending?.cleanup?.();
|
||||
throw error;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,6 +317,27 @@ describe("GatewayClient", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("cleans pending request state when websocket send throws", async () => {
|
||||
const client = new GatewayClient({
|
||||
requestTimeoutMs: 25,
|
||||
});
|
||||
const sendError = new Error("synthetic send failure");
|
||||
(
|
||||
client as unknown as {
|
||||
ws: WebSocket | { readyState: number; send: () => void; close: () => void };
|
||||
}
|
||||
).ws = {
|
||||
readyState: WebSocket.OPEN,
|
||||
send: vi.fn(() => {
|
||||
throw sendError;
|
||||
}),
|
||||
close: vi.fn(),
|
||||
};
|
||||
|
||||
await expect(client.request("status")).rejects.toThrow("synthetic send failure");
|
||||
expect(getPendingCount(client)).toBe(0);
|
||||
});
|
||||
|
||||
test("does not auto-timeout expectFinal requests", async () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user