Is there an existing issue for this?
Describe the bug
In a dot net core 8 application, health checks executed on a regular interval eventually leak all available memory, causing the container to crash.
Expected Behavior
Health check should not leak memory. Memory usage should remain relatively consistent or at least be reclaimed by garbage collection.
Steps To Reproduce
Reproduced with the following system configuration:
- Windows 11 build 22631.3155
- SDK: 8.0.102
- Runtime: 8.0.2
- Setup new dot net core web API application using .NET 8 as the target framework
- Modify the auto generated
Program.cs to include the following block of code
builder.Services.AddHealthChecks();
var app = builder.Build();
app.MapHealthChecks("/hc", new HealthCheckOptions
{
AllowCachingResponses = false,
});
From there, run the program with a memory profiler (I used DotMemory version 2023.3.3). Notice that each time /hc is called, the health check leaks ~100KB of RAM.
Now, modify the *.csproj file to change the target framework to dot net 6;
<TargetFramework>net6.0</TargetFramework>
Note:
- You will need to remove the OpenAPI reference in the
*.csproj
- You will also need to remove the
.WithOpenApi(); extension in Program.cs
Now repeat the profiling exercise. Notice that, although the memory is not 100% constant, it doesn't really exhibit "leaking" behavior.
Please advise as to how to proceed. If you setup a docker container to poll the service at ~10 second intervals, you'll end up with hundreds of MBs of RAM leaked over a few hour timeframe.
Severity: SEVERE; risk of production crash. Framework is effectively not usable.
Exceptions (if any)
Memory should not leak during basic health check.
.NET Version
8.0.102
Anything else?
Similar to issue reported in the runtime itself, dotnet/runtime#99304
Is there an existing issue for this?
Describe the bug
In a dot net core 8 application, health checks executed on a regular interval eventually leak all available memory, causing the container to crash.
Expected Behavior
Health check should not leak memory. Memory usage should remain relatively consistent or at least be reclaimed by garbage collection.
Steps To Reproduce
Reproduced with the following system configuration:
Program.csto include the following block of codeFrom there, run the program with a memory profiler (I used DotMemory version 2023.3.3). Notice that each time
/hcis called, the health check leaks ~100KB of RAM.Now, modify the
*.csprojfile to change the target framework to dot net 6;<TargetFramework>net6.0</TargetFramework>Note:
*.csproj.WithOpenApi();extension inProgram.csNow repeat the profiling exercise. Notice that, although the memory is not 100% constant, it doesn't really exhibit "leaking" behavior.
Please advise as to how to proceed. If you setup a docker container to poll the service at ~10 second intervals, you'll end up with hundreds of MBs of RAM leaked over a few hour timeframe.
Severity: SEVERE; risk of production crash. Framework is effectively not usable.
Exceptions (if any)
Memory should not leak during basic health check.
.NET Version
8.0.102
Anything else?
Similar to issue reported in the runtime itself, dotnet/runtime#99304