Skip to content

Commit

Permalink
dh: Tweak Retry handler to log retryAttempt 0 also encore
Browse files Browse the repository at this point in the history
  • Loading branch information
rmandvikar committed Oct 29, 2023
1 parent a800aac commit 7c8c1bc
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ protected override async Task<HttpResponseMessage> SendAsync(
medianFirstRetryDelay: TimeSpan.FromMilliseconds(retrySettings.RetryDelayInMilliseconds),
retryCount: retrySettings.RetryCount).ToArray();
var context = new Context();
context[ContextKey.RetryAttempt] = 0;
context[ContextKey.SleepDurations] = sleepDurationsWithJitter;

var tuple = await retryPolicy.ExecuteAsync(
action: async (context, ct) =>
{
var retryAttempt = context.TryGetValue(ContextKey.RetryAttempt, out var retryAttemptObj) ? retryAttemptObj : 0;
var retryAttempt = (int)context[ContextKey.RetryAttempt];
request.Properties[RequestProperties.PollyRetryAttempt] = retryAttempt;
var response = await base.SendAsync(request, ct)
.ConfigureAwait(false);
Expand All @@ -104,7 +105,7 @@ private bool CanRetry(
return false;
}
// retryAttempt is 0-based
var retryAttempt = context.TryGetValue(ContextKey.RetryAttempt, out object retryAttemptObj) ? (int)retryAttemptObj : 0;
var retryAttempt = (int)context[ContextKey.RetryAttempt];
if (retryAttempt == sleepDurationsWithJitter.Count())
{
return false;
Expand Down

0 comments on commit 7c8c1bc

Please sign in to comment.