fix(browser-files): report exhausted object URL leases as retryable (02-04)
Preview and download share one lease registry and download leases stay for a 30 s grace, so running out of slots clears on its own. Only a Blob above the single-lease ceiling stays LIMIT_EXCEEDED without retry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c8e4794860
commit
0b41cb38af
@@ -31,6 +31,7 @@ import {
|
||||
} from "./file-observer.ts";
|
||||
import {
|
||||
ObjectUrlLeaseRegistry,
|
||||
objectUrlLimitFailure,
|
||||
type ObjectUrlLease,
|
||||
} from "./object-url-lease.ts";
|
||||
import { BrowserFilePolicyRegistry } from "./browser-file-policy-registry.ts";
|
||||
@@ -1032,7 +1033,7 @@ function mapDownloadException(
|
||||
return browserDataFailure("INTEGRITY_FAILED", "DOWNLOAD");
|
||||
}
|
||||
if (error.name === "FileTooLargeError") {
|
||||
return browserDataFailure("LIMIT_EXCEEDED", "DOWNLOAD");
|
||||
return objectUrlLimitFailure(error, "DOWNLOAD");
|
||||
}
|
||||
}
|
||||
return mapBrowserDataException(error, "DOWNLOAD");
|
||||
|
||||
@@ -45,6 +45,31 @@ const DEFAULT_OBJECT_URL_LEASE_LIMITS: ObjectUrlLeaseLimits =
|
||||
hardMaxAggregateLeaseBytes: 256 * 1024 * 1024,
|
||||
});
|
||||
|
||||
/**
|
||||
* 02-04. Every lease slot or the aggregate byte budget is in use. Leases free
|
||||
* up when released (a download after its revoke grace), so unlike one Blob
|
||||
* above the single-lease ceiling this is reported as retryable.
|
||||
*/
|
||||
class ObjectUrlLeasesExhaustedError extends DOMException {
|
||||
constructor() {
|
||||
super("Object URL leases exhausted", "FileTooLargeError");
|
||||
}
|
||||
}
|
||||
|
||||
/** Maps a `FileTooLargeError` from the registry or a byte cap. */
|
||||
export function objectUrlLimitFailure(
|
||||
error: DOMException,
|
||||
operation: "PREVIEW" | "DOWNLOAD",
|
||||
): BrowserDataResult<never> {
|
||||
return browserDataFailure(
|
||||
"LIMIT_EXCEEDED",
|
||||
operation,
|
||||
error instanceof ObjectUrlLeasesExhaustedError
|
||||
? { retryable: true, recovery: "RETRY" }
|
||||
: {},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The only low-level owner of object URL creation/revocation. Every lease is
|
||||
* idempotent and dispose() is a final safety net for route/runtime teardown.
|
||||
@@ -97,17 +122,21 @@ export class ObjectUrlLeaseRegistry {
|
||||
create(blob: Blob): ObjectUrlLease {
|
||||
if (
|
||||
!isValidByteLength(blob.size) ||
|
||||
blob.size > this.#limits.hardMaxSingleLeaseBytes ||
|
||||
this.#active.size >= this.#limits.hardMaxActiveLeases ||
|
||||
!Number.isSafeInteger(this.#aggregateByteLength + blob.size) ||
|
||||
this.#aggregateByteLength + blob.size >
|
||||
this.#limits.hardMaxAggregateLeaseBytes
|
||||
blob.size > this.#limits.hardMaxSingleLeaseBytes
|
||||
) {
|
||||
throw new DOMException(
|
||||
"Object URL lease limit exceeded",
|
||||
"FileTooLargeError",
|
||||
);
|
||||
}
|
||||
if (
|
||||
this.#active.size >= this.#limits.hardMaxActiveLeases ||
|
||||
!Number.isSafeInteger(this.#aggregateByteLength + blob.size) ||
|
||||
this.#aggregateByteLength + blob.size >
|
||||
this.#limits.hardMaxAggregateLeaseBytes
|
||||
) {
|
||||
throw new ObjectUrlLeasesExhaustedError();
|
||||
}
|
||||
const url = this.#createObjectURL(blob);
|
||||
if (typeof url !== "string" || url.length === 0) {
|
||||
throw new DOMException(
|
||||
@@ -303,9 +332,7 @@ export class BrowserTransientPreview implements TransientPreviewPort {
|
||||
error instanceof DOMException &&
|
||||
error.name === "FileTooLargeError"
|
||||
) {
|
||||
return this.#observe(
|
||||
browserDataFailure("LIMIT_EXCEEDED", "PREVIEW"),
|
||||
);
|
||||
return this.#observe(objectUrlLimitFailure(error, "PREVIEW"));
|
||||
}
|
||||
return this.#observe(mapBrowserDataException(error, "PREVIEW"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user