Bug #42801 ClearPool .Net connector : NullReferenceException
Submitted: 12 Feb 2009 18:52 Modified: 3 Apr 2009 13:46
Reporter: Guillaume M Email Updates:
Status: Closed Impact on me:
Category:Connector / NET Severity:S2 (Serious)
Version:5.2.5 OS:Microsoft Windows (Windows Seven 64)
Assigned to: CPU Architecture:Any
Tags: ClearPool, connector, exception, MySqlConnection, null, reference

[12 Feb 2009 18:52] Guillaume M
I got a null reference exception when calling MySqlConnection.ClearPool(connection)

How to repeat:
Create a connection (do not Open it) and call MySqlConnection.ClearPool(connection)
[12 Feb 2009 19:03] Guillaume M
And of course, connection is not null ;) I double checked it.
[12 Feb 2009 20:13] Tonci Grgin
Hi Guillaume and thanks for your report.

I hate to say this but you'll get same answer for second one.
>> This does not look like bug report at all <<

Please attach small but *complete* test case demonstrating this problem each time I run it. Also, please include all necessary info for successful recreation of environment (in this case MySQL server version, .NET FW version ...).
[13 Mar 2009 0:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[24 Mar 2009 7:36] Bogdan Degtyariov
Clearing connection pool twice for different MysqlConnection objects can result in a null-reference exception. If one MysqlConnection has already cleaned the connection pool, repeating the same procedure will cause referencing of non-existing hash table element.

How to repeat:
Run the following C# code

MySqlConnectionStringBuilder builder = new

builder.MinimumPoolSize = 0;
builder.Pooling = true;
builder.Server = "localhost";
builder.UserID = "*****";
builder.Password = "******";
builder.PersistSecurityInfo = false;
MySqlConnection connection1 = null;
MySqlConnection connection2 = null;
            connection1 = new
            connection2 = new



catch (Exception ex)
            string error = ex.Message.ToString();
            error+= ex.StackTrace;

Suggested fix:

Index: MySql.Data/Provider/Source/MySqlPoolManager.cs
--- MySql.Data/Provider/Source/MySqlPoolManager.cs	(revision 1526)
+++ MySql.Data/Provider/Source/MySqlPoolManager.cs	(working copy)
@@ -90,6 +90,11 @@
                 // add the pool to our list of pools being cleared
                 MySqlPool pool = (pools[key] as MySqlPool);
+                // Check if the pool has already been cleared
+                if (pool == null)
+                    return;
                 // now tell the pool to clear itself

This bug affects version 6.0 as well
[25 Mar 2009 17:29] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

[25 Mar 2009 17:35] Reggie Burnett
fixed in 5.2.6 and 6.0+
[3 Apr 2009 13:46] Tony Bedford
An entry was added to the 5.2.6 and 6.0.0 changelogs:

A null reference exception was generated when MySqlConnection.ClearPool(connection) was called.