dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.95k stars 4.65k forks source link

Unmanaged memory growth with DiagnosticsClient #105132

Open vaind opened 1 month ago

vaind commented 1 month ago

Description

I'm running a diagnostic session on the program itself (for in-process profiling) and am facing issues noticable in ASP.NET core apps, although I think it's only showing there due to the number of events being produced.

Reproduction Steps

I've created a simple app which just connects a diagnostic session and ignores incoming events:

  1. dotnet new webapi --use-controllers -o webapi
  2. dotnet add package Microsoft.Diagnostics.Tracing.TraceEvent --version 3.1.13
  3. dotnet add package Microsoft.Diagnostics.NETCore.Client --version 0.2.510501
  4. set "System.GC.HeapHardLimit": 5242880 in runtimeconfig to make sure GC runs early
  5. update Program.cs, see repo: https://github.com/vaind/webapi-mem
  6. dotnet build -c Release
  7. run the program and observe unmanaged memory growth

Expected behavior

I'd expect the unmanaged memory to cap at the given circularBufferMB: 16 + some baseline for the runtime of course.

Actual behavior

Memory grows over time:

image

And after a few hours:

image

Regression?

No response

Known Workarounds

No response

Configuration

.NET SDK:
 Version:           8.0.303
 Commit:            29ab8e3268
 Workload version:  8.0.300-manifests.7ccdde63
 MSBuild version:   17.10.4+10fbfbf2e

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.303\

Other information

No response

dotnet-policy-service[bot] commented 1 month ago

Tagging subscribers to this area: @tommcdon See info in area-owners.md if you want to be subscribed.

bruno-garcia commented 4 days ago

Any help on this will be much appreciated.