Skip to content

Fix Infinity overflow in retry backoff calculation - #1246

Open
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/promise-retry-overflow-protection
Open

Fix Infinity overflow in retry backoff calculation#1246
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/promise-retry-overflow-protection

Conversation

@pavankumar-vh

Copy link
Copy Markdown

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. Then Math.round(Infinity * jitter) returns Infinity, and setTimeout with Infinity would never fire, causing the retry to hang forever.

Fix

Added Number.isFinite() check to cap the delay at Number.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 protection

Scope

This change only touches common/ which is an approved contribution area per the Contributing Guide.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant