List:Commits« Previous MessageNext Message »
From:Vladislav Vaintroub Date:November 24 2009 7:55pm
Subject:bzr commit into connector-net-trunk branch (vvaintroub:800) Bug#31996
View as plain text  
#At file:///H:/connector_net/trunk/t1/ based on revid:reggie.burnett@stripped

  800 Vladislav Vaintroub	2009-11-24
      - Always close connection in MySqlConnection.Dispose(), also when it is garbage-collected
        so underlying driver can be reused in the connection pool (bug#31996)

    modified:
      CHANGES
      MySql.Data/Provider/Source/Connection.cs
      MySql.Data/Provider/Source/Driver.cs
      MySql.Data/Provider/Source/MySqlPool.cs
      MySql.Data/Tests/Source/ConnectionTests.cs
=== modified file 'CHANGES'
--- a/CHANGES	2009-11-11 20:17:35 +0000
+++ b/CHANGES	2009-11-24 19:55:41 +0000
@@ -1,3 +1,5 @@
+- Always close connection in MySqlConnection.Dispose(), also when it is garbage-collected
+  so underlying driver can be reused in the connection pool (bug#31996)
 Version 6.2.1
 - fixed SessionProvider to be compatible with 4.x MySQL, replaced TIMESTAMPDIFF with TIME_TO_SEC
   (bug#47219)

=== modified file 'MySql.Data/Provider/Source/Connection.cs'
--- a/MySql.Data/Provider/Source/Connection.cs	2009-11-20 17:04:03 +0000
+++ b/MySql.Data/Provider/Source/Connection.cs	2009-11-24 19:55:41 +0000
@@ -518,7 +518,7 @@ namespace MySql.Data.MySqlClient
 
         protected override void Dispose(bool disposing)
         {
-            if (disposing && State == ConnectionState.Open)
+            if (State == ConnectionState.Open)
                 Close();
             base.Dispose(disposing);
         }

=== modified file 'MySql.Data/Provider/Source/Driver.cs'
--- a/MySql.Data/Provider/Source/Driver.cs	2009-11-20 17:04:03 +0000
+++ b/MySql.Data/Provider/Source/Driver.cs	2009-11-24 19:55:41 +0000
@@ -88,6 +88,7 @@ namespace MySql.Data.MySqlClient
         public MySqlConnection Connection
         {
             get { return connection; }
+            set { connection = value; }
         }
 
         public int ThreadID

=== modified file 'MySql.Data/Provider/Source/MySqlPool.cs'
--- a/MySql.Data/Provider/Source/MySqlPool.cs	2009-11-20 17:04:03 +0000
+++ b/MySql.Data/Provider/Source/MySqlPool.cs	2009-11-24 19:55:41 +0000
@@ -47,6 +47,7 @@ namespace MySql.Data.MySqlClient
         private void EnqueueIdle(Driver driver)
         {
             driver.IdleSince = DateTime.Now;
+            driver.Connection = null;
             idlePool.Enqueue(driver);
         }
 		public MySqlPool(MySqlConnectionStringBuilder settings)

=== modified file 'MySql.Data/Tests/Source/ConnectionTests.cs'
--- a/MySql.Data/Tests/Source/ConnectionTests.cs	2009-08-31 19:32:51 +0000
+++ b/MySql.Data/Tests/Source/ConnectionTests.cs	2009-11-24 19:55:41 +0000
@@ -366,6 +366,29 @@ namespace MySql.Data.MySqlClient.Tests
             }
         }
 
+
+        class ConnectionClosedCheck
+        {
+            public bool closed = false;
+            public void stateChangeHandler(object sender, StateChangeEventArgs e)
+            {
+                if (e.CurrentState == ConnectionState.Closed)
+                    closed = true;
+            }
+        }
+        [Test]
+        public void ConnectionCloseByGC()
+        {
+            ConnectionClosedCheck check = new ConnectionClosedCheck();
+            string connStr = GetConnectionString(true);
+            MySqlConnection c = new MySqlConnection(connStr);
+            c.StateChange += new StateChangeEventHandler(check.stateChangeHandler);
+            c.Open();
+            c = null;
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+            Assert.IsTrue(check.closed);
+        }
 		/// <summary>
 		/// Bug #30964 StateChange imperfection 
 		/// </summary>


Attachment: [text/bzr-bundle] bzr/vvaintroub@mysql.com-20091124195541-7uz6tucwozqjzbqt.bundle
Thread
bzr commit into connector-net-trunk branch (vvaintroub:800) Bug#31996Vladislav Vaintroub24 Nov