Skip to content

Connection timeout if MySqlDataReader isn't disposed #306

Description

@bgrainger

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions