fix(event-stream): cancel unavailable upstream bodies (#1142)

Co-authored-by: Isaac Sanchez <isanchez-hawkins@arize.com>
This commit is contained in:
Isaac Sanchez-Hawkins
2026-05-08 15:14:39 +03:00
committed by GitHub
co-authored by Isaac Sanchez
parent 47fc6a4606
commit 4a79af3fb7
2 changed files with 18 additions and 1 deletions
@@ -31,6 +31,12 @@ function normalizeHeaders(headers) {
return { ...headers };
}
async function cancelResponseBody(response) {
if (response?.body && typeof response.body.cancel === 'function') {
await response.body.cancel().catch(() => {});
}
}
export function createUpstreamSseReader({
buildUrl,
getHeaders = () => ({}),
@@ -116,6 +122,7 @@ export function createUpstreamSseReader({
status: response?.status ?? 0,
response,
});
await cancelResponseBody(response);
await waitForReconnectDelay(reconnectDelayMs, signal);
continue;
}