Bug #29756 MySql .Net Driver unable to retrieve MySql server connection after shutdown
Submitted: 12 Jul 2007 13:20 Modified: 21 Jul 2010 21:20
Reporter: christophe rouz Email Updates:
Status: Unsupported Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:5.0.7, 5.2 svn OS:Linux (Debian)
Assigned to: Reggie Burnett CPU Architecture:Any
Tags: connector, MySQL, server, shutdown

[12 Jul 2007 13:20] christophe rouz
Description:
Hello,

i had a problem with MySql connector .Net 5.0.7

My application is using this driver, and during a shutdown / restart of the MySql database server, as my application was still living, it happened that the driver (used in a pooling way) didn't manage to retrieve the connection to the database after restart : it raised once "UnableToConnectToHost" exception, then all the following errors were "TimeoutGettingConnection".

The Semaphore MySqlPool.poolGate was, in fact, never resetted as the last connections failed into exceptions.

How to repeat:
- Start an app that uses the mysql .net connector, writing often into the database. Here is my connection string : 

server=192.168.0.1; database=db_name; port=3306; uid=uid; password=password; pooling=true; charset=utf8; connect timeout=1; min pool size=0; max pool size=100; connection lifetime=5

- Stop MySql Server

- Restart MySql Server

- Timeout errors should continue to be raised

Suggested fix:
- Just make the poolGate to be resetted after a driver.Open() exception
[27 Jul 2007 11:24] Tonci Grgin
Hi christophe and thanks for your report.

Verified as described. Latest SVN sources produce different error though: "Reading from stream has failed". Toggling connection reset true/false makes no difference.

Environment:
 - MySQL server 5.0.44BK on WinXP Pro SP2 localhost
 - NET FW 2.0 with latest c/NET sources

    MySqlConnection conn = new MySqlConnection();
    conn.ConnectionString = "server=localhost; database=mysql; port=3306; uid=root; password=tonchika; pooling=true; charset=utf8; connect timeout=1; min pool size=0; max pool size=100; connection lifetime=5; connection reset=true";
    conn.Open();
    MySqlCommand cmd = new MySqlCommand();
    cmd.Connection = conn;
    cmd.CommandTimeout = 0;
    cmd.CommandType = CommandType.Text;
    cmd.CommandText = "SELECT 1+1";
    cmd.ExecuteScalar();
//put a BP or dialog here and restart server.
    cmd.CommandText = "SELECT 2+2"; // << Reading from ...
    cmd.ExecuteScalar();
[19 Feb 2009 16:27] Tonci Grgin
Still a bug in 5.2 svn branch against MySQL server 5.1.30GA.
[20 Apr 2009 6:30] Tonci Grgin
Reggie?
[22 Apr 2009 12:21] Tonci Grgin
Since bug is verified ages ago, I rechecked and exception changed (5.2 branch):
"Fatal error encountered during command execution."
[10 Jun 2009 9:42] Tonci Grgin
Bug#38796 was marked as duplicate of this report. Reggie?
[2 Dec 2009 0:23] Jonathan LaRue
Just encountered this bug as well.  Here's a reliable way to reproduce the bug using SSH Port forwarding:

# Create SSH session with option "-L 3307:localhost:3306".  This will port forward 3307 to your own 3306.  (assumes mysql server is on localhost)

connectionString= "database=localhost;port=3307;user=user;pass=pass"
conn = new MySQLConnection(connectionString)
conn.open()
MsgBox("Hooray I'm open!")
conn.close()
MsgBox("Please destroy then recreate ssh session. Click ok when done")
#Manually destroy SSH session, then recreate SSH session
conn.open()

Hope this helps-
Jonathan
[21 Jul 2010 21:20] Reggie Burnett
I tested this with the latest 6.0 release and couldn't reproduce.  I don't believe it is a problem any longer.