Skip to content

Conversation

dev-kas
Copy link

@dev-kas dev-kas commented Sep 20, 2025

Description

This PR fixes a panic in retryDelay that occurs when the computed delay becomes negative due to integer overflow in time.Duration for large retryCount values

Problem

  • The existing exponential backoff calculation (0.5 * 2^retryCount * time.Second) can exceed the maximum int64 for time.Duration, wrapping around to negative values.
  • While I was using the API, the panic was observed at retryCount = 35, where the computed delay wrapped to -9223372036854775808.
  • When delay is negative, the subsequent rand.Int63n(delay/4) call panics.

Fix

  • Clamp delay to a safe range [1s, maxDelay] before applying jitter.
  • Ensure the jitter argument to rand.Int63n is always >= 1 second, preventing it from receiving invalid (<=0) arguments.
  • Subtract jitter safely from the clamped delay.

Impact

  • Prevents panics on high retry counts.
  • Maintains existing exponential backoff behavior within reasonable limits.

@dev-kas dev-kas requested a review from a team as a code owner September 20, 2025 23:10
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