fix: Long retry-after would generate timeout instead of RateLimitException

Needed to move the retry handler before the TimeOut handler, and drive the throw from the TimeOut configured by the user for the provider.
This commit is contained in:
omgbeez 2026-03-14 09:32:51 -04:00 committed by Clifford Roche
parent 41787077db
commit 76dc3e0b98

View file

@ -92,11 +92,6 @@ public static class DiConfig
private static void ConfigureResiliencePipeline(ResiliencePipelineBuilder<HttpResponseMessage> builder)
{
builder.AddTimeout(new TimeoutStrategyOptions
{
TimeoutGenerator = _ => new(TimeSpan.FromSeconds(Settings.Get.Provider.Timeout))
});
builder.AddRateLimitHeaders(options =>
{
options.EnableProactiveThrottling = true;
@ -120,8 +115,9 @@ public static class DiConfig
if (args.Outcome.Result is { StatusCode: HttpStatusCode.TooManyRequests } response)
{
var delay = RateLimitHandler.GetRetryAfterDelay(response);
var timeout = TimeSpan.FromSeconds(Settings.Get.Provider.Timeout);
if (delay >= TimeSpan.FromMinutes(10))
if (delay >= timeout)
{
return new ValueTask<TimeSpan?>((TimeSpan?)null);
}
@ -132,5 +128,10 @@ public static class DiConfig
return new((TimeSpan?)null);
}
});
builder.AddTimeout(new TimeoutStrategyOptions
{
TimeoutGenerator = _ => new(TimeSpan.FromSeconds(Settings.Get.Provider.Timeout))
});
}
}