mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 00:18:27 +00:00
fix(cli): stop waiting for the cloud's file check when the caller aborts (#7361)
This commit is contained in:
@@ -399,6 +399,7 @@ export async function completeWithRetry(
|
||||
asset_id: string,
|
||||
checksum_sha256: string,
|
||||
sizeBytes: number,
|
||||
signal?: AbortSignal,
|
||||
): Promise<{ asset_id: string; url: string }> {
|
||||
const budget = completeBudgetMs(sizeBytes);
|
||||
const startedAt = Date.now();
|
||||
@@ -415,7 +416,11 @@ export async function completeWithRetry(
|
||||
{ cause: err },
|
||||
);
|
||||
}
|
||||
await sleep(Math.min(poll, left));
|
||||
await sleep(Math.min(poll, left), signal);
|
||||
if (signal?.aborted)
|
||||
throw new Error("Stopped waiting for the cloud to finish checking the uploaded file.", {
|
||||
cause: signal.reason,
|
||||
});
|
||||
poll = Math.min(poll * 2, completeWait.maxPollMs);
|
||||
}
|
||||
}
|
||||
@@ -472,6 +477,7 @@ export async function uploadAssetViaDirectUpload(
|
||||
initialize.asset_id,
|
||||
checksum_sha256,
|
||||
size_bytes,
|
||||
opts.signal,
|
||||
).catch((err: unknown) => {
|
||||
throw nameRefusedFile(err, filename, opts.contentType);
|
||||
});
|
||||
|
||||
@@ -33,7 +33,7 @@ describe("completeWithRetry waits for the check as long as the file's size allow
|
||||
expect(completeBudgetMs(100_000 * MIB)).toBe(600_000);
|
||||
});
|
||||
|
||||
it("keeps polling through two minutes of 409s on a big file, then returns the asset", async () => {
|
||||
it("keeps polling through more than a minute of 409s on a big file, then returns the asset", async () => {
|
||||
const { client, complete } = clientAnswering(
|
||||
...Array.from({ length: 20 }, () => "409" as const),
|
||||
"ok",
|
||||
@@ -69,4 +69,18 @@ describe("completeWithRetry waits for the check as long as the file's size allow
|
||||
await expect(completeWithRetry(client, "a1", "sha", 1 * MIB)).rejects.toBe(refused);
|
||||
expect(complete).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("stops waiting when the caller aborts", async () => {
|
||||
const { client, complete } = clientAnswering();
|
||||
const controller = new AbortController();
|
||||
|
||||
const done = completeWithRetry(client, "a1", "sha", 600 * MIB, controller.signal);
|
||||
const aborted = expect(done).rejects.toThrow(/Stopped waiting for the cloud/);
|
||||
await vi.advanceTimersByTimeAsync(1_000);
|
||||
controller.abort(new Error("cancelled"));
|
||||
await vi.advanceTimersByTimeAsync(1);
|
||||
|
||||
await aborted;
|
||||
expect(complete.mock.calls.length).toBeLessThan(6);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user