fix(e2e): cancel kitchen probe body reads on abort

This commit is contained in:
Vincent Koc
2026-06-19 07:13:55 +02:00
parent 6368c1173c
commit 5776b9b4e6
2 changed files with 39 additions and 3 deletions

View File

@@ -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 {

View File

@@ -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({