fix: contain immich stream cancel races
This commit is contained in:
1 parent
653e5ca050
commit
0fe2c80cda
2 files changed
+23
-1
No files matched your search
@@ -182,6 +182,28 @@ test("maps a caller abort during a binary stream to IMMICH_ABORTED", async () =>
|
||||
await expect(read).rejects.toMatchObject({ code: "IMMICH_ABORTED" });
|
||||
});
|
||||
|
||||
test("contains an upstream binary cancel rejection after caller abort", async () => {
|
||||
const caller = new AbortController();
|
||||
const streamingClient = createImmichClient({
|
||||
baseUrl,
|
||||
apiKey,
|
||||
fetch: async () => {
|
||||
const body = new ReadableStream<Uint8Array>({
|
||||
cancel() {
|
||||
return Promise.reject(new Error("upstream cancel race"));
|
||||
},
|
||||
});
|
||||
return new Response(body, { headers: { "content-type": "image/jpeg" } });
|
||||
},
|
||||
});
|
||||
|
||||
const original = await streamingClient.getOriginal("asset-1", caller.signal);
|
||||
const read = original.body.getReader().read();
|
||||
caller.abort();
|
||||
|
||||
await expect(read).rejects.toMatchObject({ code: "IMMICH_ABORTED" });
|
||||
});
|
||||
|
||||
test("preserves abort, timeout, and network failures while reading JSON bodies", async () => {
|
||||
const caller = new AbortController();
|
||||
const abortedClient = createImmichClient({
|
||||
|
||||
@@ -261,7 +261,7 @@ export function createImmichClient({
|
||||
}
|
||||
const error = failureError(lifecycle);
|
||||
finish();
|
||||
void reader.cancel(error);
|
||||
void reader.cancel(error).catch(() => undefined);
|
||||
controller.error(error);
|
||||
};
|
||||
lifecycle.signal.addEventListener("abort", abortStream, { once: true });
|
||||
|
||||
Reference in new issue
Block a user