dotnet / dotnet/AspNetCore.Docs
Problems with IHealthChecksBuilder.AddTypeActivatedCheck<T> in Microsoft.Extensions.DependencyInjection.HealthChecksBuilderAddCheckExtensions
- Dominant language
- C#
- Stars
- 13.1k
- Forks
- 24.6k
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 97
Description
AddTypeActivatedCheck support additional arguments to concert type constructor which implements IHealthCheck.
This sounds good idea, but it brought few issues.
First, I feel it is not really needed.
More important, it might cause memory leak.
It resolves (some) HealthCheck constructor arguments from IoC container, and not resolve HealthCheck itself from Ioc container ( to support additional constructor arguments). This bring few issues:
The runtime create particular HealthCheck instance each time Health end point is hit. Since itself is not managed by Ioc container, lifetime does not apply to it. Ioc container cannot dispose it even it is a IDisposable. Heath check Runtime just create it but does not dispose it either. Application cannot dispose it since it was not created by application itself.
So it was created each time when health check is performed and never disposed. That can cause resource/memory leak.
I call it memory leak introduced by Ioc container leak -- HealthCheck instances are not managed by Ioc container, but their dependencies are. Those dependencies are referred by HealthCheck but their lifetime can out of sync, this can cause another type issue.
---
#### Document Details
⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*
* ID: c0cbb094-29e9-740a-9fd6-db372641d753
* Version Independent ID: 52d8efc9-a336-71d9-6d90-98173cbf6bf4
* Content: [Health checks in ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-6.0)
* Content Source: [aspnetcore/host-and-deploy/health-checks.md](https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/host-and-deploy/health-checks.md)
* Product: **aspnet-core**
* Technology: **aspnetcore-hostdeploy**
* GitHub Login: @Rick-Anderson
* Microsoft Alias: **riande**
Contributor guide
Assessment
This issue has not been assessed yet.