csharp icon indicating copy to clipboard operation
csharp copied to clipboard

Memory Leak with aot package ListDeployments and ListStatefulSet

Open guillaume-chervet opened this issue 11 months ago • 9 comments

Describe the bug SlimFaas is calling ListDeployments and ListStatefulSet every Second (in the futur we will use watch). I think of memory leak because memory increase without ending. Previous version worked on production without any crash with 180Mo of RAM set and the same code. The only change is the switch to AOT packages.

If I remove calls, the memory keep very stable.

https://github.com/AxaFrance/SlimFaas/blob/main/src/SlimFaas/ReplicasSynchronizationWorker.cs https://github.com/AxaFrance/SlimFaas/blob/main/src/SlimFaas/Kubernetes/KubernetesService.cs

All RAM goes down in the graph bellow are OOM Killed. image

Kubernetes C# SDK Client Version "KubernetesClient.Aot" Version="13.0.12"

Dotnet Runtime Version .NET 8

guillaume-chervet avatar Mar 10 '24 12:03 guillaume-chervet

Is it possible to analyze some memory info from a dump?

Think the HttpRequestMessage/HttpResponseMessage and the HttpContent should be disposed, maybe we could try to add using for them firstly

image

WeihanLi avatar Mar 10 '24 16:03 WeihanLi

Hi fixed it in my side by this commit https://github.com/AxaFrance/SlimFaas/commit/d71b2ba065f416ae22bd0340407c928e9226e051

But it is still a bug it seem dispose does not dispose well.

I will try to memory dump.

guillaume-chervet avatar Mar 10 '24 16:03 guillaume-chervet

yes dump please i will try to repo by calling list

tg123 avatar Mar 10 '24 16:03 tg123

I had a add week, i will try to do it next week!

guillaume-chervet avatar Mar 16 '24 21:03 guillaume-chervet

i ran the load test last weekend for whole afternoon, but did not see any leak. code is simple

for(;;) { listdeployment; sleep 5s}

tg123 avatar Mar 28 '24 00:03 tg123

my test code

using k8s;

var config = KubernetesClientConfiguration.BuildDefaultConfig();
IKubernetes client = new Kubernetes(config);
Console.WriteLine("Starting Request!");


for (; ;){
    var list = client.AppsV1.ListDeploymentForAllNamespaces();
    foreach (var item in list.Items)
    {
        Console.WriteLine(item.Metadata.Name);
    }

    Thread.Sleep(5000);
    GC.Collect();
}


tg123 avatar Apr 07 '24 03:04 tg123

Hi @tg123 @WeihanLi

I was creating disposing a new Kubernetes client at each iteration.

guillaume-chervet avatar Apr 07 '24 06:04 guillaume-chervet

I still have now a tigth memory leak. 10 Mo in 2 productions week. But i have to investigate to know the source.

guillaume-chervet avatar Apr 07 '24 06:04 guillaume-chervet

image

tg123 avatar Apr 07 '24 06:04 tg123