Fix Infinity overflow in retry backoff calculation - #1246
Conversation
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.
|
Thanks for tracking this down — the overflow scenario is real: with enough retry attempts, On the fix itself: capping at This also has no accompanying test, and the repo doesn't have existing tests for Right instinct, but the numeric ceiling chosen doesn't actually solve the practical problem of overly long retry delays, and it needs a test to be portable as-is. |
Overview
Fix Infinity overflow in retry backoff calculation in
common/src/util/promise.ts.Bug Description
The function used
Math.pow(2, attempt)which can overflow to Infinity if attempt is large. ThenMath.round(Infinity * jitter)returns Infinity, andsetTimeoutwith Infinity would never fire, causing the retry to hang forever.Fix
Added
Number.isFinite()check to cap the delay atNumber.MAX_SAFE_INTEGER.Testing
No existing tests for this function, but the fix prevents infinite hangs.
Files Changed
common/src/util/promise.ts- Added overflow protectionScope
This change only touches
common/which is an approved contribution area per the Contributing Guide.