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

Connection is not closed even if the program exited #545

Closed
shwuhk opened this issue Aug 8, 2018 · 6 comments
Closed

Connection is not closed even if the program exited #545

shwuhk opened this issue Aug 8, 2018 · 6 comments
Assignees
Labels

Comments

@shwuhk
Copy link

shwuhk commented Aug 8, 2018

I am using MariaDB and EF Core 2. The connection string is optionsBuilder.UseMySql("server=1.1.1.1;port=3306;user=user;password=password;database=dbName;TreatTinyAsBoolean=false");
and try with the following code.

static async Task Main(string[] args)
{
  using (var dbContext = new MyDbContext()) {
    var d = await dbContext.MyEntity.FindAsync("id");
  }
}

After the program exit, I find that there is some sleeping connection in the database and it will exist for around ten minutes. This will end up using all of our connections if we restart the program for many times.
Is it a bug of by design or I should do anything else to clean up all the connections?

@shwuhk
Copy link
Author

shwuhk commented Aug 8, 2018

I find that I can avoid this problem if I call MySql.Data.MySqlClient.MySqlConnection.ClearAllPools() when the program exit. Is this a intended behavior for the user to call this before the program exit? It is quite weird if we need to as I suppose this should not be managed by us but EF(?)?

@bgrainger
Copy link
Member

bgrainger commented Aug 8, 2018

MySqlConnector currently has no automatic cleanup on process exit; it's up to the user of the library to call MySqlConnection.ClearAllPools on process exit.

We should consider attaching an event handler to AppDomain.ProcessExit that calls MySqlConnection.ClearAllPools in the full .NET Framework builds, for feature parity with Connector/NET.

@shwuhk
Copy link
Author

shwuhk commented Aug 8, 2018

I think this is good as all connections should be handled by Connector/Net and the user has no idea what is doing behind and thus, it seems doesn't make sense if the user need to touch the MySqlConnection library.

@ejball
Copy link
Contributor

ejball commented Aug 9, 2018

@bgrainger, you've probably seen this already, but just in case: https://github.com/dotnet/corefx/issues/10012

@bgrainger
Copy link
Member

bgrainger commented Aug 14, 2018

System.Runtime.Loader (referenced from that corefx issue) is only supported on netstandard1.5 and higher; I can't find a solution for netstandard1.3.

However, for all other MySqlConnector platforms (net45 and later, netstandard2.0 and later, netcoreapp2.1 and later), AppDomain.Current.ProcessExit is available and can be used to implement this feature.

@bgrainger bgrainger self-assigned this Aug 14, 2018
@bgrainger bgrainger added the bug label Aug 14, 2018
@bgrainger
Copy link
Member

Fixed in 0.44.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants