From d159db2f27d0a7df0b960966776d80352b848519 Mon Sep 17 00:00:00 2001 From: Pavan Kumar VH Date: Thu, 3 Sep 2026 15:53:31 +0530 Subject: [PATCH] Fix Infinity overflow in retry backoff calculation The function used Math.pow(2, attempt) which can overflow to Infinity if attempt is large. Then Math.round(Infinity * jitter) returns Infinity, and setTimeout with Infinity would never fire, causing the retry to hang forever. Added Number.isFinite() check to cap the delay at Number.MAX_SAFE_INTEGER. --- common/src/util/promise.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/src/util/promise.ts b/common/src/util/promise.ts index acf26a35dd..d4a9c983c8 100644 --- a/common/src/util/promise.ts +++ b/common/src/util/promise.ts @@ -32,8 +32,9 @@ export async function withRetry( // Exponential backoff with jitter (±20%) to prevent thundering herd const baseDelayMs = retryDelayMs * Math.pow(2, attempt) + const safeBaseDelayMs = Number.isFinite(baseDelayMs) ? baseDelayMs : Number.MAX_SAFE_INTEGER const jitter = 0.8 + Math.random() * 0.4 // Random multiplier between 0.8 and 1.2 - const delayMs = Math.round(baseDelayMs * jitter) + const delayMs = Math.round(safeBaseDelayMs * jitter) await new Promise((resolve) => setTimeout(resolve, delayMs)) } }