Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak SqlConnectionFactory #2406

Open
Juandavi1 opened this issue Mar 14, 2024 · 5 comments · May be fixed by #2420
Open

Memory Leak SqlConnectionFactory #2406

Juandavi1 opened this issue Mar 14, 2024 · 5 comments · May be fixed by #2420
Labels
💡 Enhancement New feature request

Comments

@Juandavi1
Copy link

Juandavi1 commented Mar 14, 2024

Describe the bug

Hi !

We have a multi-tenant db model. Each user has a different connection string.

We have a base class that creates the connections and data accessors.

Something like this:

image


This is our invocation


image


This is our gcdump


image


This is our Memory Graph

image

Further technical details

Microsoft.Data.SqlClient version: 5.2.0
.NET target: net 6
SQL Server version: Azure sql database Level compatibility 160 Version 16
Operating system: Docker

Additional context

We've already conducted tests with pooling set to both true and false, and the problem persists.

Our connection string looks like this:


server={0};uid={1};pwd={2};database={3};connection timeout=5;pooling=true;Max Pool Size=100;Workstation ID=Microservices;Connection Lifetime=60;Application Name=ms-memory;

At night, when traffic is zero, the memory does not decrease.
We also tried calling the garbage collector (GC) manually, and the memory decreased by a few MB.

@DavoudEshtehari DavoudEshtehari added this to Needs triage in SqlClient Triage Board via automation Mar 15, 2024
@javiermendozain
Copy link

Hi @DavoudEshtehari and @Juandavi1

In this PR, some memory leaks have been fixed.
#2420

@DavoudEshtehari DavoudEshtehari moved this from Needs triage to Under Investigation in SqlClient Triage Board Mar 26, 2024
@DavoudEshtehari DavoudEshtehari added 💡 Enhancement New feature request and removed untriaged labels Mar 26, 2024
@DavoudEshtehari
Copy link
Member

Thank you for proposing the PR. We'll look into it.

@Juandavi1
Copy link
Author

Juandavi1 commented Mar 28, 2024

Hi ! We found something. We are calling SqlConnection.ClearPool() after each query and the memory leak disappear. However the performance increase a lot !

I was wondering 🤔 Is there a way to have the same pool for diferente connections? Do you know? @DavoudEshtehari

@Juandavi1
Copy link
Author

DapperLib/Dapper#1759

@Juandavi1
Copy link
Author

If we set pooling to false, throws a too many noon-pooled connections exception

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 Enhancement New feature request
Projects
SqlClient Triage Board
  
Under Investigation
Development

Successfully merging a pull request may close this issue.

3 participants