Corrige la logique de jitter pour garantir une augmentation du délai dans le mécanisme de retry

This commit is contained in:
2025-11-10 23:05:03 +01:00
parent 971f063b39
commit a6fbe9c72e

View File

@@ -68,8 +68,8 @@ export class Retry {
attempt += 1
const retry = isRetryable ? isRetryable(e) : true
if (!retry || attempt >= this.policy.maxAttempts) break
// FIXED: Jitter should always increase delay, not decrease it (remove the -1)
const jitter = 1 + Math.random() * this.policy.jitter
// Apply jitter: vary delay by ±jitter% (e.g., jitter=0.2 means ±20%)
const jitter = 1 + (Math.random() * 2 - 1) * this.policy.jitter
const sleep = Math.min(this.policy.maxDelay, Math.max(0, Math.floor(delay * jitter)))
await new Promise((r) => setTimeout(r, sleep))
delay = Math.min(this.policy.maxDelay, Math.floor(delay * (this.policy.multiplier || 2)))