Bug #29217 Use of semaphores non-released
Submitted: 19 Jun 2007 15:18 Modified: 24 Jul 2007 14:32
Reporter: Emiliano Ritiro Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:5.0.7 OS:Windows (Windows Xp Professional SP2 - .NET v2.0)
Assigned to: CPU Architecture:Any

[19 Jun 2007 15:18] Emiliano Ritiro
Description:
si no se puede abrir una conexion, 
luego de una determinada cantidad de reintentos se provoca una 
MySqlException(Resources.TimeoutGettingConnection)

Detalle:
"error connecting: Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached."

How to repeat:
1º Cierre el servidor de MySQL
2º Intente conectar el cliente MySql mediante la instrucción MySqlConnection.Open() la cantidad de veces necesarias hasta que el se obtenga la excepcion antedicha. "error connecting: Timeout..."

3º Reestablezca la comunicación con el servidor de MySql

¡El cliente ya no se reconectará!

Ej:

            //Primero Cierre el servidor de datos!!!!
            DbConnection Conexion=null;
            for(int i=0;i<1000;i++)
            {
               Conexion = new MySql.Data.MySqlClient.MySqlConnection();
               Conexion.ConnectionString = "database=...  ";
               try{
               Conexion.Open();
               }catch(Exception){};
            }

            //Reconecte el servidor
            Conexion.Open();

throws:
"error connecting: Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached."

Suggested fix:
En MySqlPool.cs :

Modifique GetConnection()
Con el siguiente codigo:
	
public Driver GetConnection() 
{
int ticks = (int)settings.ConnectionTimeout * 1000;

// wait till we are allowed in
bool allowed = poolGate.WaitOne(ticks, false);
if (! allowed)
throw new MySqlException(Resources.TimeoutGettingConnection);

// if we get here, then it means that we either have an idle connection
// or room to make a new connection
lock (lockObject)
{
try
{
return GetPooledConnection();
}
catch (Exception)
{
// if an exception occurs releases the pool gate
poolGate.Release();
throw;
}
}
}
[20 Jun 2007 20:55] Tonci Grgin
Hola Emiliano. 
Thanks for your report. Note that we accept reports only in English. Can you please attach full test case exhibiting this error every time you run it as want to see your connection string and the rest of code. Also, attach my.ini/cnf file from server and please translate report to English.
[21 Jun 2007 12:20] Emiliano Ritiro
If a connection cannot be opened, after a certain amount on attempts a MySqlException(Resources.TimeoutGettingConnection) is caused.

Description:
"error connecting: Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  
This may have occurred because all pooled connections were in use and max pool size was reached."

But no one connection is in use!

If the connection recovers, the system no longer will be connected.

I hope you understand me.
[22 Jun 2007 6:23] Tonci Grgin
Emiliano, thanks for your effort, report looks ok to me now.

Can you please follow the rest of instructions:
"Can you please attach full test case exhibiting this error every time you run it as want to see your connection string and the rest of code. Also, attach my.ini/cnf file from server."
[22 Jul 2007 23: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 Jul 2007 14:32] Reggie Burnett
This is a duplicate of 29409 which has been fixed in 1.0.10, 5.0.8, and 5.1.3