Skip to content

Memory leak issue found in 8.0.4 Kubernetes C# Client SDK #1123

@Moresoph

Description

@Moresoph

Describe the bug
Kubernetes Csharp client has a memory leak problem when using the leader election functionality.

Kubernetes C# SDK Client Version
8.0.4

Server Kubernetes Version
Server Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.8", GitCommit:"83d00b7cbf10e530d1d4b2403f22413220c37621", GitTreeState:"clean", BuildDate:"2022-11-09T19:50:11Z", GoVersion:"go1.17.11", Compiler:"gc", Platform:"linux/amd64"}

Dotnet Runtime Version
.net 3.1 core

To Reproduce
image

Where do you run your app with Kubernetes SDK (please complete the following information):

  • OS: Linux
  • Environment container
  • Cloud Azure

Additional context
Here is my investigation of this memory leak problem.
When we use the leader election functionality, we find that memory increases over time.

The following picture shows that the count of the object named "Linked1CancelaationTokenSource" increased greatly.
image

The following picture shows the call stack of how the KubernetesClient will call the function named "CreateLinkedTokenSource" to create the object named "Linked1CancelaationTokenSource".
image

The following picture shows the decompiled code from version 8.0.4 "KubernetesClient.Basic.dll". From the following decompiled code we can see, the "Dispose()" function of the "CancellationTokenSource cts" is not called.
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions