The following code will eventually throw a MySqlConnection "Connect Timeout expired" and leave the pool full of idle but unusable sessions.
while (true)
{
var connection = new MySqlConnection(csb.ConnectionString);
connection.Open();
var cmd = connection.CreateCommand();
cmd.CommandText = "SELECT 1";
var reader = cmd.ExecuteReader();
while (reader.Read()) { }
GC.Collect(); // to try to force objects to be cleaned up
}
In MySqlConnector, this happens because there's a strong reference from MySqlSession to MySqlCommand and MySqlDataReader, and from those to MySqlConnection, so the WeakReference-based code never works.
This also fails in MySql.Data, so it's not a new bug. However, it would be nice to fix it so that "invalid" use of the library doesn't make connection pools unusable.
The text was updated successfully, but these errors were encountered:
This looks a lot like what is happening here. A some points during the day, I have these sudden bursts of mysql exceptions saying "Connect Timeout expired". I thought they were due to more connections being open with real async and the idle connections filling up the pool, but if that is the case, a GC happening at a very specific time could be cause this too.
The code to recover leaked sessions depends on MySqlConnection being GCed. If MySqlSession holds strong references to MySqlConnection (via MySqlCommand or MySqlDataReader), then failure to dispose a MySqlDataReader will leak the connection.
The following code will eventually throw a
MySqlConnection
"Connect Timeout expired" and leave the pool full of idle but unusable sessions.In MySqlConnector, this happens because there's a strong reference from
MySqlSession
toMySqlCommand
andMySqlDataReader
, and from those toMySqlConnection
, so theWeakReference
-based code never works.This also fails in MySql.Data, so it's not a new bug. However, it would be nice to fix it so that "invalid" use of the library doesn't make connection pools unusable.
The text was updated successfully, but these errors were encountered: