@@ -594,8 +594,8 @@ await _activityTracer.TraceActivityAsync(async activity =>
594594 {
595595 lastException = ex ;
596596
597- // Calculate backoff with jitter
598- int waitMs = CalculateBackoffWithJitter ( currentBackoffMs ) ;
597+ // Exponential backoff with jitter (80-120% of base)
598+ int waitMs = ( int ) Math . Max ( 100 , currentBackoffMs * ( 0.8 + new Random ( ) . NextDouble ( ) * 0.4 ) ) ;
599599
600600 // Check if we would exceed the retry time budget
601601 int retryTimeoutMs = _retryTimeoutSeconds * 1000 ;
@@ -628,7 +628,7 @@ await _activityTracer.TraceActivityAsync(async activity =>
628628 ] ) ;
629629
630630 await Task . Delay ( waitMs , cancellationToken ) . ConfigureAwait ( false ) ;
631- currentBackoffMs = Math . Min ( currentBackoffMs * 2 , MaxBackoffMs ) ;
631+ currentBackoffMs = Math . Min ( currentBackoffMs * 2 , 32_000 ) ;
632632 }
633633 }
634634
@@ -759,22 +759,6 @@ private void CompleteWithError(Activity? activity = null)
759759 }
760760 }
761761
762- /// <summary>
763- /// Maximum backoff time in milliseconds for exponential backoff (32 seconds).
764- /// </summary>
765- private const int MaxBackoffMs = 32_000 ;
766-
767- /// <summary>
768- /// Calculates backoff time with jitter to avoid thundering herd problem.
769- /// Same algorithm as RetryHttpHandler.
770- /// </summary>
771- private static int CalculateBackoffWithJitter ( int baseBackoffMs )
772- {
773- Random random = new Random ( ) ;
774- double jitterFactor = 0.8 + ( random . NextDouble ( ) * 0.4 ) ; // Between 0.8 and 1.2
775- return ( int ) Math . Max ( 100 , baseBackoffMs * jitterFactor ) ;
776- }
777-
778762 // Helper method to sanitize URLs for logging (to avoid exposing sensitive information)
779763 private string SanitizeUrl ( string url )
780764 {
0 commit comments