Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Exception when adding multiple PolicyHandler #29

Open
angelaki opened this issue Nov 1, 2021 · 1 comment
Open

Exception when adding multiple PolicyHandler #29

angelaki opened this issue Nov 1, 2021 · 1 comment

Comments

@angelaki
Copy link

angelaki commented Nov 1, 2021

With the current .net Version 6.0 I get this exception on execution when adding multiple PolicyHandlers:

An item with the same key has already been added. Key: PolicyHttpMessageHandler.PriorResponse.

Right now I'm adding these two PoliciHandlers to my IHttpClientBuilder:

    .AddPolicyHandler(GetRetryPolicy())
    .AddPolicyHandler(GetTimeoutPolicy())

    public IAsyncPolicy<HttpResponseMessage> GetRetryPolicy(int retryCount = 5)
        => HttpPolicyExtensions
            .HandleTransientHttpError()
            .Or<TimeoutRejectedException>()
            .OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.NotFound)
            .OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.Unauthorized)
            .WaitAndRetryAsync(retryCount, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt - 1)))
        ;

    public IAsyncPolicy<HttpResponseMessage> GetTimeoutPolicy(TimeSpan? timeout = null)
        => Policy.TimeoutAsync<HttpResponseMessage>(timeout ?? TimeSpan.FromSeconds(100));

Is this a known issue? It was working before .net 6.0.

@angelaki
Copy link
Author

angelaki commented Nov 1, 2021

It seams to be a .Net issue since no Polly lib needs to be involved. I've created an issue there, too:

dotnet/runtime#61056

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant