fix(discord): widen rate-limit jitter to de-sync parallel retries
The 250ms jitter was too narrow for ~68 parallel refresh reads — all retries clustered after the same retry_after and collided again. Scale jitter linearly with attempt number so the herd progressively spreads out across attempts.
This commit is contained in:
parent
ffa85f0109
commit
9c7f6f3051
1 changed files with 4 additions and 1 deletions
|
|
@ -50,7 +50,10 @@ async function discordFetch<T>(
|
|||
|
||||
if (response.status === 429) {
|
||||
const body = (await response.json()) as DiscordRateLimitResponse;
|
||||
const retryAfterMs = Math.ceil(body.retry_after * 1000) + Math.random() * 250;
|
||||
// Linearly increasing jitter de-syncs the thundering herd when many
|
||||
// resources refresh in parallel and all receive the same retry_after.
|
||||
const jitterMs = Math.random() * 1000 * (attempt + 1);
|
||||
const retryAfterMs = Math.ceil(body.retry_after * 1000) + jitterMs;
|
||||
lastError = new Error(
|
||||
`Discord API rate limited on ${endpoint} (retry_after=${body.retry_after}s, global=${body.global})`
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue