fix(crestodian): cancel gateway probe bodies · openclaw/openclaw@dfc5bd5
vincentkoc
·
2026-06-19
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -6,6 +6,7 @@ import { probeGatewayUrl, probeLocalCommand } from "./probes.js";
|
6 | 6 | describe("crestodian probes", () => { |
7 | 7 | afterEach(() => { |
8 | 8 | vi.restoreAllMocks(); |
| 9 | +vi.unstubAllGlobals(); |
9 | 10 | }); |
10 | 11 | |
11 | 12 | it("bounds noisy local command probe output", async () => { |
@@ -54,4 +55,26 @@ describe("crestodian probes", () => {
|
54 | 55 | |
55 | 56 | expect(timeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS); |
56 | 57 | }); |
| 58 | + |
| 59 | +it("cancels gateway health response bodies", async () => { |
| 60 | +const cancel = vi.fn(async () => undefined); |
| 61 | +vi.stubGlobal( |
| 62 | +"fetch", |
| 63 | +vi.fn( |
| 64 | +async () => |
| 65 | +({ |
| 66 | +ok: false, |
| 67 | +statusText: "Service Unavailable", |
| 68 | +body: { cancel }, |
| 69 | +}) as unknown as Response, |
| 70 | +), |
| 71 | +); |
| 72 | + |
| 73 | +await expect(probeGatewayUrl("ws://127.0.0.1:1234")).resolves.toEqual({ |
| 74 | +reachable: false, |
| 75 | +url: "ws://127.0.0.1:1234", |
| 76 | +error: "Service Unavailable", |
| 77 | +}); |
| 78 | +expect(cancel).toHaveBeenCalledTimes(1); |
| 79 | +}); |
57 | 80 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -116,8 +116,9 @@ export async function probeGatewayUrl(
|
116 | 116 | const timeoutMs = resolveTimerTimeoutMs(opts.timeoutMs, 900); |
117 | 117 | const controller = new AbortController(); |
118 | 118 | const timeout = setTimeout(() => controller.abort(), timeoutMs); |
| 119 | +let response: Response | undefined; |
119 | 120 | try { |
120 | | -const response = await fetch(healthUrl, { |
| 121 | +response = await fetch(healthUrl, { |
121 | 122 | method: "GET", |
122 | 123 | signal: controller.signal, |
123 | 124 | }); |
@@ -130,5 +131,6 @@ export async function probeGatewayUrl(
|
130 | 131 | }; |
131 | 132 | } finally { |
132 | 133 | clearTimeout(timeout); |
| 134 | +await response?.body?.cancel().catch(() => undefined); |
133 | 135 | } |
134 | 136 | } |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。