Skip to content

DefaultHealthCheckService throws exception  #45873

Open
@Vshishkar

Description

@Vshishkar

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Based on the code at HealthCheckPubliserHosterService DefaultHealthCheckService should not throw exceptions, but if there is exception on initialization of a health check service doesn't properly handle it, which leads to failure of publishing health report.

For example if there is a dependency of a health check which is not registered in container, health check initialization would throw exception.

Expected Behavior

HealthCheckService would return failed with failure of health check.

It's arguable whether failure of health check initialization should be reported the same as failure of logic within health check, but it must be reported in some way.

Steps To Reproduce

Create a simple health check with missing dependency:

	public class NonWorkingHealthCheck : IHealthCheck
	{
		public NonWorkingHealthCheck(string param, IDependency dep) {}
		
		public Task<HealthCheckResult> CheckHealthAsync(
		    HealthCheckContext context,
		    CancellationToken cancellationToken = default)
		         => Task.FromResult(HealthCheckResult.Healthy());

        interface IDependency {}

And register this health check:

builder.AddTypeActivatedCheck<NonWorkingHealthCheck>("NonWorking", "param1");

Exceptions (if any)

No response

.NET Version

7.0

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.area-healthchecksIncludes: Healthchecks (some bugs also in Extensions repo)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions