MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Vladislav Vaintroub Date:July 7 2010 1:37pm
Subject:bzr commit into connector-net-trunk branch (vvaintroub:891) Bug#54681
View as plain text  
#At file:///H:/connector_net/trunk/ based on revid:reggie.burnett@stripped

  891 Vladislav Vaintroub	2010-07-07
      - Fix null reference exception when TransactionScope is used by multiple threads
       (bug#54681 , fix contributed by Erskine Thompson)

    modified:
      CHANGES
      MySql.Data/Provider/Source/MySqlPromotableTransaction.cs
      MySql.Data/Tests/Source/Transactions.cs
=== modified file 'CHANGES'
--- a/CHANGES	2010-07-02 18:41:31 +0000
+++ b/CHANGES	2010-07-07 13:37:03 +0000
@@ -1,3 +1,5 @@
+- Fix null reference exception when TransactionScope is used by multiple threads
+ (bug#54681, fix contributed by Erskine Thompson)
 - Ensure exceptions are not silently eaten inside MySqlDataReader.Read()  (Bug#53439)
 - Cancel query in ThreadAbortException handler (Bug#54012)
 - Call DataTable.AcceptChanges() for affected tables at the end of MySqlAdapter.Update, 

=== modified file 'MySql.Data/Provider/Source/MySqlPromotableTransaction.cs'
--- a/MySql.Data/Provider/Source/MySqlPromotableTransaction.cs	2010-01-13 22:59:43 +0000
+++ b/MySql.Data/Provider/Source/MySqlPromotableTransaction.cs	2010-07-07 13:37:03 +0000
@@ -86,7 +86,7 @@ namespace MySql.Data.MySqlClient
     {
         // Per-thread stack to manage nested transaction scopes
         [ThreadStatic]
-        static Stack<MySqlTransactionScope> globalScopeStack = new Stack<MySqlTransactionScope>();
+        static Stack<MySqlTransactionScope> globalScopeStack;
 
         MySqlConnection connection;
         Transaction baseTransaction;
@@ -136,6 +136,11 @@ namespace MySql.Data.MySqlClient
            // We need to save the per-thread scope stack locally.
            // We cannot always use thread static variable in rollback: when scope
            // times out, rollback is issued by another thread.
+           if (globalScopeStack == null)
+           {
+               globalScopeStack = new Stack<MySqlTransactionScope>();
+           }
+
            scopeStack = globalScopeStack;
            scopeStack.Push(new MySqlTransactionScope(connection, baseTransaction, 
               simpleTransaction));

=== modified file 'MySql.Data/Tests/Source/Transactions.cs'
--- a/MySql.Data/Tests/Source/Transactions.cs	2010-01-13 22:59:43 +0000
+++ b/MySql.Data/Tests/Source/Transactions.cs	2010-07-07 13:37:03 +0000
@@ -637,5 +637,35 @@ namespace MySql.Data.MySqlClient.Tests
                 Assert.AreEqual(0, count);
             }
         }
+
+
+        /// <summary>
+        /// Bug#54681 : Null Reference exception when using transaction
+        /// scope in more that one thread
+        /// </summary>
+        [Test]
+        public void TransactionScopeWithThreads()
+        {
+            // use transaction scope in the current thread
+            DoThreadWork();
+
+            //use transaction scope in another thread (used to crash with null
+            // reference exception)
+            Thread t = new Thread(new ThreadStart(DoThreadWork));
+            t.Start();
+            t.Join();
+        }
+
+        private void DoThreadWork()
+        {
+            using (TransactionScope ts = new TransactionScope())
+            {
+                string connStr = GetConnectionString(true);
+                using (MySqlConnection c1 = new MySqlConnection(connStr))
+                {
+                    c1.Open();
+                }
+            }
+        }
     }
 }


Attachment: [text/bzr-bundle] bzr/vvaintroub@mysql.com-20100707133703-rh1c6nnevmyhkfl6.bundle
Thread
bzr commit into connector-net-trunk branch (vvaintroub:891) Bug#54681Vladislav Vaintroub7 Jul