mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-09 03:22:40 +00:00
fix(e2e): cancel kitchen probe body reads on abort
This commit is contained in:
@@ -918,10 +918,12 @@ export async function fetchJson(url, options = {}) {
|
||||
timeoutPromise,
|
||||
...(abortPromise ? [abortPromise] : []),
|
||||
]);
|
||||
const bodyAbortPromise = abortPromise
|
||||
? Promise.race([timeoutPromise, abortPromise])
|
||||
: timeoutPromise;
|
||||
const text = await Promise.race([
|
||||
readBoundedResponseText(response, maxBodyBytes, timeoutPromise),
|
||||
timeoutPromise,
|
||||
...(abortPromise ? [abortPromise] : []),
|
||||
readBoundedResponseText(response, maxBodyBytes, bodyAbortPromise),
|
||||
bodyAbortPromise,
|
||||
]);
|
||||
let body = null;
|
||||
try {
|
||||
|
||||
@@ -1968,6 +1968,40 @@ describe("kitchen-sink RPC process sampling", () => {
|
||||
expect(canceled).toBe(true);
|
||||
});
|
||||
|
||||
it("cancels stalled HTTP probe response streams when the external signal fires", async () => {
|
||||
let readStarted = false;
|
||||
let canceled = false;
|
||||
const controller = new AbortController();
|
||||
const fetchImpl = vi.fn().mockResolvedValue(
|
||||
new Response(
|
||||
new ReadableStream({
|
||||
pull() {
|
||||
readStarted = true;
|
||||
return new Promise(() => {});
|
||||
},
|
||||
cancel() {
|
||||
canceled = true;
|
||||
},
|
||||
}),
|
||||
{ status: 200 },
|
||||
),
|
||||
);
|
||||
|
||||
const result = fetchJson("http://127.0.0.1:19680/readyz", {
|
||||
attempts: 1,
|
||||
fetchImpl,
|
||||
signal: controller.signal,
|
||||
timeoutMs: 30_000,
|
||||
});
|
||||
const rejection = expect(result).rejects.toThrow("gateway exited before ready");
|
||||
|
||||
await waitFor(() => readStarted);
|
||||
controller.abort(new Error("gateway exited before ready"));
|
||||
|
||||
await rejection;
|
||||
await waitFor(() => canceled);
|
||||
});
|
||||
|
||||
it("times out stalled HTTP probe response bodies", async () => {
|
||||
vi.useFakeTimers();
|
||||
const fetchImpl = vi.fn().mockResolvedValue({
|
||||
|
||||
Reference in New Issue
Block a user