Skip to content

Use of RetryDelegatingHandler with IHttpClientFactory #1026

Closed
@krispenner

Description

@krispenner

Issue Summary

The RetryDelegatingHandler is not used when using IHttpClientFactory. In order to manually register it, it requires that the base DelegatingHandler class have it default ctor called which is not the case with the current implementation.

This is what I'm trying to do...

Steps to Reproduce

Services
    .AddSingleton(new ReliabilitySettings(2, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(2)))
    .AddTransient<RetryDelegatingHandler>()
    .AddHttpClient(nameof(SendGrid))
    .AddHttpMessageHandler<RetryDelegatingHandler>()
    .ConfigureHttpClient(httpClient =>
    {
        httpClient.Timeout = TimeSpan.FromSeconds(60);
    });

Changes that would fix this is to call base default ctor instead of creating a new HttpClientHandler.

Change this line to the below:

public RetryDelegatingHandler(ReliabilitySettings settings)
// remove this line
//  : this(new HttpClientHandler(), settings)
{
    // add this line
    this.settings = settings;
}

Was there a specific reason to create an HttpClientHandler? If so, maybe need a InjectableRetryDelegatingHandler class specific for this use case.

Or is there any other option for this? The only other option I can think of is to make my own retry handler or use Polly but I would prefer to use the one created specifically by SendGrid for SendGrid. Seems reasonable to expect this to work.

Exception/Log

The 'InnerHandler' property must be null. 'DelegatingHandler' instances provided to 'HttpMessageHandlerBuilder' must not be reused or cached. Handler: 'SendGrid.Helpers.Reliability.RetryDelegatingHandler'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions