Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Health Check Fails - HTTP/2 over TLS was not negotiated on an HTTP/2-only endpoint

I've enabled HTTP2-only for my APIs. However, when attempting to use health checks I get the following error

HTTP/2 over TLS was not negotiated on an HTTP/2-only endpoint.

Setup looks like this

Kestrel:

"Kestrel": {
"EndpointDefaults": {
  "Protocols": "Http2",
  "Http": {
    "Url": "http://localhost:5020"
  }
}

},

Health Check:

public static IServiceCollection AddCustomHealthCheck(this IServiceCollection services)
{
    var sqlOptions = services.GetOptions<SqlOptions>("ConnectionStrings");
    var rabbitMqOptions = services.GetOptions<RabbitMqOptions>("RabbitMq");

    services.AddHealthChecks()
        .AddSqlServer(sqlOptions.DefaultConnection)
        .AddRabbitMQ(rabbitConnectionString:
            $"amqp://{rabbitMqOptions.UserName}:{rabbitMqOptions.Password}@{rabbitMqOptions.HostName}");

    services.AddHealthChecksUI(setup =>
    {
        setup.SetEvaluationTimeInSeconds(60); // time in seconds between check
        setup.AddHealthCheckEndpoint("Basic Health Check", "/healthz");
    }).AddInMemoryStorage();

    return services;
}

public static WebApplication UseCustomHealthCheck(this WebApplication app)
{
    app.UseHealthChecks("/healthz",
            new HealthCheckOptions
            {
                Predicate = _ => true,
                ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse,
                ResultStatusCodes =
                {
                    [HealthStatus.Healthy] = StatusCodes.Status200OK,
                    [HealthStatus.Degraded] = StatusCodes.Status500InternalServerError,
                    [HealthStatus.Unhealthy] = StatusCodes.Status503ServiceUnavailable
                }
            })
        .UseHealthChecksUI(options =>
        {
            options.ApiPath = "/healthcheck";
            options.UIPath = "/healthcheck-ui";
        });

    return app;
}

Dotnet 6.

like image 585
Matt Avatar asked Sep 06 '25 03:09

Matt


1 Answers

I managed to resolve this by telling the health check client to specifically use HTTP version 2.0 with the following code.

        services.AddHealthChecksUI(setup =>
        {
            setup.ConfigureApiEndpointHttpclient((sp, client) =>
            {
                client.DefaultRequestVersion = new Version(2, 0);
            });
            setup.SetEvaluationTimeInSeconds(60); // time in seconds between check
            setup.AddHealthCheckEndpoint("Basic Health Check", "/healthz");
        })
        .AddInMemoryStorage();
like image 161
Matt Avatar answered Sep 09 '25 21:09

Matt