forked from Tadrisino/MathApp_frontend
Spread retries over 1-2x Retry-After so a crowd turned away together does not return together
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -81,7 +81,9 @@ export interface HttpClientOptions {
|
||||
const RETRIABLE_STATUS = new Set([408, 425, 429, 500, 502, 503, 504]);
|
||||
|
||||
function backoffMs(attempt: number, retryAfterMs?: number): number {
|
||||
if (retryAfterMs != null) return Math.min(retryAfterMs, 30_000);
|
||||
// Retry-After کمینه است، نه زمانِ دقیق: وقتی سرور زیرِ بار هزاران گوشی را همزمان رد میکند، اگر همه
|
||||
// دقیقاً بعد از همان چند ثانیه برگردند همان اوج دوباره ساخته میشود. پس بینِ ۱ تا ۲ برابرِ آن پخش میشوند.
|
||||
if (retryAfterMs != null) return Math.min(retryAfterMs * (1 + Math.random()), 30_000);
|
||||
return Math.random() * Math.min(1000 * 2 ** attempt, 8000);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user