/** * Broker-internal safe retry policy for the Azure Blob SDK. * * The default `@azure/storage-blob` retry policy (`maxTries: 4, * maxRetryDelayInMs: 120_000`) holds each in-flight request's body in * memory for up to 2 minutes between retry attempts. Under storage-account * throttle (503 ServerBusy, IngressOverAccountLimit), concurrent retries * pile up their retained bodies in `process.memoryUsage().arrayBuffers`, * which under sustained high rate exhausts the container heap and triggers * a cgroup OOM. The workaround belongs inside the broker, not in * caller-side configuration. * * This module provides {@link cloneBlobServiceClientWithSafeRetry}, which * takes the caller's `BlobServiceClient` (built with whatever credential * shape they prefer — connection string, account key, SAS URL, managed * identity, workload identity, custom `TokenCredential`) and produces a * NEW client with the same URL + same auth but with the broker's tight * retry policy applied. The caller's original client is unmodified, so * any other application code sharing the client retains its own policy. * * Design constraints (see ADR-0020): * * - **No `instanceof` against third-party classes.** Class identity is * unstable across SDK versions, bundler tree-shaking, and esbuild * `class-fields` transforms. * - **No private-field access.** We use the public `client.credential` * property that `@azure/storage-blob` exposes on its * `StorageClient` base. That property carries one of three * credential shapes — `StorageSharedKeyCredential`, * `AnonymousCredential`, or a `TokenCredential` instance — and * the SDK's constructor accepts all three. We pass it through * unchanged. */ import { type BlobServiceClient, type StorageRetryOptions } from '@azure/storage-blob'; /** * The broker's safe retry policy for high-rate concurrent Azure Blob * operations. Tight retry budget + short max delay bounds in-flight * request-body retention regardless of caller-side configuration. * * Rationale: * - `maxTries: 2` — single retry. Under sustained throttle, additional * retries amplify the body-retention cascade without improving * observed success rate. The broker's own polling cadence + lease * protocol handles transient failures at the broker layer. * - `tryTimeoutInMs: 30_000` — bounded per-request wait. Without a * cap, lease re-acquires have been observed hanging for tens of * minutes on the SDK's default policy. * - `maxRetryDelayInMs: 1_000` — back-off ceiling. Default 120 s lets * bodies linger for two minutes per retry; capped at 1 s keeps the * cumulative in-flight queue bounded. * - `retryDelayInMs: 100` — first-retry delay. Short enough to absorb * genuine transient blips (e.g. SDK socket reset) without amplifying. */ export declare const BROKER_SAFE_RETRY_OPTIONS: StorageRetryOptions; /** * One HTTP attempt per call, for the producer's leased conditional appends * (ADR-0030). An SDK-internal retry hides an earlier attempt that may have * committed behind a final error such as a lease code or a 4xx, which the * producer would then take as proof nothing landed; its own retry loop reads * back between attempts instead. */ export declare const BROKER_SINGLE_ATTEMPT_RETRY_OPTIONS: StorageRetryOptions; /** * Construct a new {@link BlobServiceClient} with the broker's safe retry * policy (or `retryOptions`) applied, preserving the source client's URL + credential. * * The caller's original client is **not modified** — anything else in * the caller's application that holds a reference to it retains the * caller's own retry policy. * * **Caveat:** only `url` + `credential` are carried over. Any custom * pipeline on the source client (proxy, extra `RequestPolicy` factories, * custom telemetry policies) is **dropped** — the clone gets a default * pipeline plus the safe retry options. Callers who need a custom pipeline * should disable the clone (`applySafeRetryPolicy: false`) and apply the * broker's safe retry tuning to their own client. * * Mechanism: reads the public `credential` property from the source * client and the public `url` property, then constructs a new * `BlobServiceClient(url, credential, { retryOptions: SAFE })`. The * SDK's constructor accepts any of `StorageSharedKeyCredential`, * `AnonymousCredential`, or a `TokenCredential`, so all three auth * shapes (connection-string / account-key, SAS-in-URL, managed identity * / workload identity / custom `TokenCredential`) round-trip cleanly. * * @param source - the caller's BlobServiceClient (any credential shape) * @param BlobServiceClientCtor - the SDK's `BlobServiceClient` * constructor, injected by the caller so this module is unit-testable * with a fake. * @returns a new BlobServiceClient identical to `source` except for the * retry policy */ export declare function cloneBlobServiceClientWithSafeRetry(source: BlobServiceClient, BlobServiceClientCtor: typeof BlobServiceClient, retryOptions?: StorageRetryOptions): BlobServiceClient; //# sourceMappingURL=safeRetry.d.ts.map