Bug #54681 | "Object reference not set to an instance of an object." with TransactionScope | ||
---|---|---|---|
Submitted: | 21 Jun 2010 23:18 | Modified: | 13 Jul 2010 9:08 |
Reporter: | Shane Marsden | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | Connector / NET | Severity: | S1 (Critical) |
Version: | 6.3.2 | OS: | Windows (Windows 7 x64) |
Assigned to: | Vladislav Vaintroub | CPU Architecture: | Any |
Tags: | .net, 6.3.2, Connector/Net, IPromotableSinglePhaseNotification, MySqlPromotableTransaction, Object reference not set to an instance of an object, transaction, TransactionScope |
[21 Jun 2010 23:18]
Shane Marsden
[21 Jun 2010 23:20]
Shane Marsden
.NET project demonstrating problem
Attachment: MvcApplication2.zip (application/x-zip-compressed, text), 292.74 KiB.
[21 Jun 2010 23:26]
Shane Marsden
To see the error, perform the following: create database x, username x, password x. run included .sql to create table web.config assumes db running on localhost tested on servers 5.1.38 GA and 5.1.48 GA run project, click Thing tab and click "Create Loads in a Loop". By the second or third time of clicking this link, you should see the error. Note that I have no problems using 6.2.3 with TransactionScopes under .NET 3.5 (but no EF support there so I don't know if it's anything to do with that).
[24 Jun 2010 9:09]
Bogdan Degtyariov
Hi Shane, Thank you for the detailed description of the problem and the test project. We shall give it a test and then come back to you with the results. Thanks.
[28 Jun 2010 6:31]
Bogdan Degtyariov
Hi Shane, I was able to repeat the problem. The Exception was thrown after the 3rd click. Setting the bug status to verified and trying to find a solution for this bug. Thanks.
[6 Jul 2010 16:45]
Erskine Thompson
Hi Bogdan, I believe I've traced the bug back to MySqlPromotableTransaction. The private member globalScopeStack is initialized at declaration and marked with the [ThreadStatic] attribute. This will work fine for the first thread but all subsequent threads will run into a null reference. I was able to resolve this issue by moving the initialization of this member to the InitializeMethod() method. Here's a copy of the unidiff: === modified file MySql.Data/Provider/Source/MySqlPromotableTransaction.cs --- MySql.Data/Provider/Source/MySqlPromotableTransaction.cs 2010-01-13 22:59:43 +0000 +++ MySql.Data/Provider/Source/MySqlPromotableTransaction.cs 2010-07-06 08:14:18 +0000 @@ -86,7 +86,7 @@ { // 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,9 @@ // 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. // Bug #54681 + if(globalScopeStack == null) + globalScopeStack = new Stack<MySqlTransactionScope>(); + scopeStack = globalScopeStack; scopeStack.Push(new MySqlTransactionScope(connection, baseTransaction, simpleTransaction));
[7 Jul 2010 13:37]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/113033 891 Vladislav Vaintroub 2010-07-07 - Fix null reference exception when TransactionScope is used by multiple threads (bug#54681 , fix contributed by Erskine Thompson)
[7 Jul 2010 13:42]
Vladislav Vaintroub
@Erskine, yes, this was it. Thanks a lot for the proposed fix! pushed to the next 6.3
[13 Jul 2010 9:08]
Tony Bedford
An entry has been added to the 6.3.3 changelog: MySQL Connector/NET generated a null reference exception when TransactionScope was used by multiple threads.