List:Commits« Previous MessageNext Message »
From:rburnett Date:July 11 2008 9:47pm
Subject:Connector/NET commit: r1335 - in branches/5.0: Driver/Source TestSuite/Source
View as plain text  
Modified:
   branches/5.0/Driver/Source/Connection.cs
   branches/5.0/Driver/Source/Driver.cs
   branches/5.0/Driver/Source/command.cs
   branches/5.0/TestSuite/Source/BaseTest.cs
   branches/5.0/TestSuite/Source/SimpleTransactions.cs
Log:
backported fix of bug #37991

Modified: branches/5.0/Driver/Source/Connection.cs
===================================================================
--- branches/5.0/Driver/Source/Connection.cs	2008-07-11 21:34:49 UTC (rev 1334)
+++ branches/5.0/Driver/Source/Connection.cs	2008-07-11 21:47:26 UTC (rev 1335)
@@ -495,7 +495,7 @@
             if (dataReader != null)
                 dataReader.Close();
 
-            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.0/Driver/Source/Driver.cs
===================================================================
--- branches/5.0/Driver/Source/Driver.cs	2008-07-11 21:34:49 UTC (rev 1334)
+++ branches/5.0/Driver/Source/Driver.cs	2008-07-11 21:47:26 UTC (rev 1335)
@@ -96,8 +96,13 @@
 			get { return hasWarnings; }
 		}
 
-		#endregion
+	    public bool IsOpen
+	    {
+            get { return isOpen; }
+	    }
 
+#endregion
+
 		public string Property(string key)
 		{
 			return (string)serverProps[key];

Modified: branches/5.0/Driver/Source/command.cs
===================================================================
--- branches/5.0/Driver/Source/command.cs	2008-07-11 21:34:49 UTC (rev 1334)
+++ branches/5.0/Driver/Source/command.cs	2008-07-11 21:47:26 UTC (rev 1335)
@@ -406,6 +406,8 @@
                         throw new MySqlException(Resources.Timeout);
                     return null;
                 }
+                if (ex.IsFatal)
+                    Connection.Close();
                 throw;
             }
             finally

Modified: branches/5.0/TestSuite/Source/BaseTest.cs
===================================================================
--- branches/5.0/TestSuite/Source/BaseTest.cs	2008-07-11 21:34:49 UTC (rev 1334)
+++ branches/5.0/TestSuite/Source/BaseTest.cs	2008-07-11 21:47:26 UTC (rev 1335)
@@ -256,9 +256,22 @@
 			{
 				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)
 		{
 			if (Is41 || Is50)

Modified: branches/5.0/TestSuite/Source/SimpleTransactions.cs
===================================================================
--- branches/5.0/TestSuite/Source/SimpleTransactions.cs	2008-07-11 21:34:49 UTC (rev 1334)
+++ branches/5.0/TestSuite/Source/SimpleTransactions.cs	2008-07-11 21:47:26 UTC (rev 1335)
@@ -111,5 +111,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: r1335 - in branches/5.0: Driver/Source TestSuite/Sourcerburnett11 Jul