fix(gateway): clean pending request when send fails · openclaw/openclaw@47cad60
vincentkoc
·
2026-06-17
·
via Recent Commits to openclaw:main
File tree
packages/gateway-client/src
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1599,7 +1599,14 @@ export class GatewayClient {
|
1599 | 1599 | }); |
1600 | 1600 | signal?.addEventListener("abort", abortHandler, { once: true }); |
1601 | 1601 | }); |
1602 | | -this.ws.send(JSON.stringify(frame)); |
| 1602 | +try { |
| 1603 | +this.ws.send(JSON.stringify(frame)); |
| 1604 | +} catch (error) { |
| 1605 | +const pending = this.pending.get(id); |
| 1606 | +this.pending.delete(id); |
| 1607 | +pending?.cleanup?.(); |
| 1608 | +throw error; |
| 1609 | +} |
1603 | 1610 | return p; |
1604 | 1611 | } |
1605 | 1612 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -317,6 +317,27 @@ describe("GatewayClient", () => {
|
317 | 317 | } |
318 | 318 | }); |
319 | 319 | |
| 320 | +test("cleans pending request state when websocket send throws", async () => { |
| 321 | +const client = new GatewayClient({ |
| 322 | +requestTimeoutMs: 25, |
| 323 | +}); |
| 324 | +const sendError = new Error("synthetic send failure"); |
| 325 | +( |
| 326 | +client as unknown as { |
| 327 | +ws: WebSocket | { readyState: number; send: () => void; close: () => void }; |
| 328 | +} |
| 329 | +).ws = { |
| 330 | +readyState: WebSocket.OPEN, |
| 331 | +send: vi.fn(() => { |
| 332 | +throw sendError; |
| 333 | +}), |
| 334 | +close: vi.fn(), |
| 335 | +}; |
| 336 | + |
| 337 | +await expect(client.request("status")).rejects.toThrow("synthetic send failure"); |
| 338 | +expect(getPendingCount(client)).toBe(0); |
| 339 | +}); |
| 340 | + |
320 | 341 | test("does not auto-timeout expectFinal requests", async () => { |
321 | 342 | vi.useFakeTimers(); |
322 | 343 | try { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。