Skip to content

Polly on Blazor #10652

@pdeveau

Description

@pdeveau

Describe the bug

Using a Polly Policy in blazor on httpclient does not execute policy on a transient failure.

To Reproduce

Steps to reproduce the behavior:
Using the code below:

using System;
using System.Collections.Generic;
using System.Net.Http;
using Microsoft.AspNetCore.Components.Builder;
using Microsoft.Extensions.DependencyInjection;
using Polly;

namespace Web.Client
{
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
             // custom wasm request handler to add a bearer token to each internally matching request
             services.AddSingleton(x => new HttpClient(new TokenWebAssemblyMessageHandler(x.GetService<ITokenService>())));

            // add polly wait and retry policy
            services.AddHttpClient<IMicroServiceClient, SomeMicroserviceClient>()
                .AddTransientHttpErrorPolicy(builder => builder.WaitAndRetryAsync(new[]
                {
                    TimeSpan.FromMilliseconds(300),
                    TimeSpan.FromMilliseconds(600),
                    TimeSpan.FromMilliseconds(900),
                    TimeSpan.FromMilliseconds(1200)
                }));

            services.AddSingleton<AppState>();
        }

        public void Configure(IComponentsApplicationBuilder app)
        {
            app.AddComponent<App>("app");
        }
    }
}

Expected behavior

When the httpclient makes a failed call, i.e. response in the 5xx and 4xx ranges, should retry the request per the orders of policy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    affected-very-fewThis issue impacts very few customersarea-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-builtin-componentsFeatures related to the built in components we ship or could ship in the futureinvestigateseverity-majorThis label is used by an internal tool

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions