Exponential backoff retry for B2 API calls.
Retries on 429 (rate limit), 408, 503, 504 (transient).
A global retry budget caps the total retry rate across all concurrent
callers. Without it, N concurrent failing calls would each retry up to
MAX_RETRIES times — a thundering herd against a struggling B2 backend.
The budget is a token bucket: at most BUDGET_TOKENS retries are allowed
per BUDGET_WINDOW_MS, and tokens refill at a steady rate.
The first attempt is never counted against the budget — only retries.
When the budget is exhausted, the original error is thrown immediately
instead of retrying.
Exponential backoff retry for B2 API calls. Retries on 429 (rate limit), 408, 503, 504 (transient).
A global retry budget caps the total retry rate across all concurrent callers. Without it, N concurrent failing calls would each retry up to MAX_RETRIES times — a thundering herd against a struggling B2 backend. The budget is a token bucket: at most BUDGET_TOKENS retries are allowed per BUDGET_WINDOW_MS, and tokens refill at a steady rate.
The first attempt is never counted against the budget — only retries. When the budget is exhausted, the original error is thrown immediately instead of retrying.