List:Commits« Previous MessageNext Message »
From:rburnett Date:July 9 2008 6:44pm
Subject:Connector/NET commit: r1331 - in branches/5.1: . Driver/Source TestSuite/Source
View as plain text  
Modified:
   branches/5.1/CHANGES
   branches/5.1/Driver/Source/Connection.cs
   branches/5.1/Driver/Source/Driver.cs
   branches/5.1/Driver/Source/command.cs
   branches/5.1/TestSuite/Source/BaseTest.cs
   branches/5.1/TestSuite/Source/SimpleTransactions.cs
Log:
Fixed problem where executing a command that results in a fatal exception would not close
the connection.  (bug #37991)


Modified: branches/5.1/CHANGES
===================================================================
--- branches/5.1/CHANGES	2008-07-08 18:33:24 UTC (rev 1330)
+++ branches/5.1/CHANGES	2008-07-09 16:44:37 UTC (rev 1331)
@@ -8,6 +8,8 @@
    autocorrection to Datetime (bug #37406)
  - Uncommented access denied error enumeration value (bug #37398)
  - Improved documentation concerning autoincrement columns and the DataColumn class (bug
#37350)
+ - Fixed problem where executing a command that results in a fatal exception would not
+   close the connection.  (bug #37991)
  
 Version 5.1.6 - 5/7/08
  - Fixed problem where parameters lists were not showing when you tried to alter a
routine 

Modified: branches/5.1/Driver/Source/Connection.cs
===================================================================
--- branches/5.1/Driver/Source/Connection.cs	2008-07-08 18:33:24 UTC (rev 1330)
+++ branches/5.1/Driver/Source/Connection.cs	2008-07-09 16:44:37 UTC (rev 1331)
@@ -569,7 +569,7 @@
 
         internal void CloseFully()
         {
-            if (settings.Pooling)
+            if (settings.Pooling && driver.IsOpen)
             {
                 // if we are in a transaction, roll it back
                 if ((driver.ServerStatus & ServerStatusFlags.InTransaction) != 0)

Modified: branches/5.1/Driver/Source/Driver.cs
===================================================================
--- branches/5.1/Driver/Source/Driver.cs	2008-07-08 18:33:24 UTC (rev 1330)
+++ branches/5.1/Driver/Source/Driver.cs	2008-07-09 16:44:37 UTC (rev 1331)
@@ -113,6 +113,11 @@
             get { return inActiveUse; }
             set { inActiveUse = value; }
         }
+
+	    public bool IsOpen
+	    {
+            get { return isOpen; }
+	    }
 #endif
 
         #endregion

Modified: branches/5.1/Driver/Source/command.cs
===================================================================
--- branches/5.1/Driver/Source/command.cs	2008-07-08 18:33:24 UTC (rev 1330)
+++ branches/5.1/Driver/Source/command.cs	2008-07-09 16:44:37 UTC (rev 1331)
@@ -415,6 +415,8 @@
                         throw new MySqlException(Resources.Timeout);
                     return null;
                 }
+                if (ex.IsFatal)
+                    Connection.Close();
                 throw;
             }
             finally

Modified: branches/5.1/TestSuite/Source/BaseTest.cs
===================================================================
--- branches/5.1/TestSuite/Source/BaseTest.cs	2008-07-08 18:33:24 UTC (rev 1330)
+++ branches/5.1/TestSuite/Source/BaseTest.cs	2008-07-09 16:44:37 UTC (rev 1331)
@@ -277,7 +277,20 @@
             {
                 Assert.Fail(ex.Message);
             }
-            c.Ping();  // this final ping will cause MySQL to clean up the killed thread
+
+            // now wait till the process dies
+            bool processStillAlive = false;
+            while (true)
+            {
+                MySqlDataAdapter da = new MySqlDataAdapter("SHOW PROCESSLIST", conn);
+                DataTable dt = new DataTable();
+                da.Fill(dt);
+                foreach (DataRow row in dt.Rows)
+                    if (row["Id"].Equals(threadId))
+                        processStillAlive = true;
+                if (!processStillAlive) break;
+                System.Threading.Thread.Sleep(500); 
+            }
         }
 
         protected void createTable(string sql, string engine)

Modified: branches/5.1/TestSuite/Source/SimpleTransactions.cs
===================================================================
--- branches/5.1/TestSuite/Source/SimpleTransactions.cs	2008-07-08 18:33:24 UTC (rev 1330)
+++ branches/5.1/TestSuite/Source/SimpleTransactions.cs	2008-07-09 16:44:37 UTC (rev 1331)
@@ -110,5 +110,40 @@
                 Assert.AreEqual("The connection is not open.", ex.Message);
             }
         }
+
+        /// <summary>
+        /// Bug #37991 Connection fails when trying to close after a commit while network
to db is bad
+        /// This test is not a perfect test of this bug as the kill connection is not
quite the
+        /// same as unplugging the network but it's the best I've figured out so far
+        /// </summary>
+        [Test]
+        public void CommitAfterConnectionDead()
+        {
+            execSQL("DROP TABLE IF EXISTS Test");
+            execSQL("CREATE TABLE Test(id INT, name VARCHAR(20))");
+
+            string connStr = GetConnectionString(true) + ";pooling=false";
+            using (MySqlConnection c = new MySqlConnection(connStr))
+            {
+                c.Open();
+                MySqlTransaction trans = c.BeginTransaction();
+
+                using (MySqlCommand cmd = new MySqlCommand("INSERT INTO Test VALUES (1,
'boo')", c))
+                {
+                    cmd.ExecuteNonQuery();
+                }
+                KillConnection(c);
+                try
+                {
+                    trans.Commit();
+                    Assert.Fail("Should have thrown an exception");
+                }
+                catch (Exception ex)
+                {
+                }
+                Assert.AreEqual(ConnectionState.Closed, c.State);
+                c.Close();    // this should work even though we are closed
+            }
+        }
 	}
 }

Thread
Connector/NET commit: r1331 - in branches/5.1: . Driver/Source TestSuite/Sourcerburnett9 Jul