dotnet / dotnet/aspnetcore

HealthCheck forcefully logs error on HealthCheckResult.Unhealthy

Open
#56,815 0 comments 1 reaction 0 assignees View on GitHub
area-healthchecks
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

When implementing a health check using the IHealthCheck interface, the service enters a "shutting down" state where it completes its current tasks before stopping. During this state, the health check returns an "unhealthy" status to prevent the service from accepting new tasks. However, this results in the health check repeatedly logging errors, which in turn triggers alerts.

### Expected Behavior

The health check should return "unhealthy" to prevent new tasks from being assigned to the service.
The system should handle the "unhealthy" status gracefully without repeatedly logging errors or triggering alert

### Steps To Reproduce

Implement a health check using the IHealthCheck interface.
Initiate the service and allow it to process tasks.
Transition the service into a "shutting down" state where it completes ongoing tasks and then stops.
Observe the health check status during the "shutting down" state.

### Exceptions (if any)

I should be able to configure the log level.

### .NET Version

8.0.300

### Anything else?

Fake errors:
![image](https://github.com/user-attachments/assets/f8e27103-d144-4854-bf6e-64c6979dcc89)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.