Skip to content

Slow but constant memory increase in .net web services on Linux #121827

@fstugren

Description

@fstugren

Description

We deploy an Asp.Net web service on AKS Linux nodes (.Net version 8.0). The service behavior is pretty standard: it accepts incoming https requests and makes outbound https requests.
All outbound requests use the HttpClient class and the IHttpClientFactory pattern. The factory creates a SocketsHttpHandler periodically and eventually replaces the old one. Http clients are created by the factory on the fly and always disposed. As far as I can tell the code always disposes the HttpResponseMessage objects it gets from HttpClient.SendAsync() calls. We don't see any SNAT port exhaustion.

Yet over time, the total memory consumed by the application pods steadily increases to the maximum allowed by the AKS deployment configuration; then eventually the pods are killed. It takes a few days to get there, but the pods invariably reach that limit. Memory goes up, garbage collector occasionally brings it down, but over time there's a steady increase. The service caches some data, but all caches eventually expire.

I captured full dumps with tools like dotnet-dump and dotnet-gcdump, but they have not been useful. All the stats reported by dotnet-dump show that the heap and the total memory consumed by the CLR (under 250MB) is much smaller than the total process memory (inching closer to 4GB)

We have not been able to identify the cause of this leak and it's affecting production services. Any ideas what we should look at? Are there any environment variables to enable so we can see more details in those dumps? It almost looks like there's an unmanaged memory leak, but I have no data yet to back this up.

Reproduction Steps

The repro consists of typically accepting inbound calls and making outbound http calls. I know it's a but vague, but I don't have something to pinpoint it now.

Expected behavior

The total memory is expected to go up and down, but it should not increase steadily over time.

Actual behavior

Total memory constantly increasing, while .net managed heap stays small.

Regression?

Unclear.

Known Workarounds

No response

Configuration

The service runs

  • Standard asp.net application on .net 8.0, current sdk version 8.0.415
  • Docker image mcr.microsoft.com/dotnet/aspnet:8.0-azurelinux3.0

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions