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 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
MySqlSessiontoMySqlCommandandMySqlDataReader, 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.