Description:
When several System.Transactions.TransactionScope instances run concurrently, MySql.Data appears to give one physical
connection to two transactions at once. Operations fail with "Got packets out of order", "This method may not be called
when another read operation is pending", "Already enlisted" and "There is already an open DataReader"; transactions are
left open on the server holding their row locks; scopes waiting on those locks hang; and intermittently the process
crashes with an unhandled NotSupportedException thrown from MySqlConnection.Finalize on the finalizer thread.
The same program with MySqlConnector 2.6.2 runs clean, and native BeginTransaction transactions are clean on both drivers.
Full repro, results and the crash stack: https://github.com/namespacedevbox/mysql-data-transactionscope-repro
Environment: MySQL Server 8.0.28 (InnoDB, REPEATABLE-READ, TLS on by default), .NET SDK 10.0.401.
Related: Bug #92465 and Bug #106398 (closed as fixed in 8.0.30) describe the same "open DataReader" on
TransactionScope.Dispose and "Already enlisted" under concurrency; both errors reproduce again on 26.7.0 with the program
above. Bug #109476 (verified, open) shows the rollback failure ("Connection must be valid and open to rollback") that
also appears here.
How to repeat:
1. Clone https://github.com/namespacedevbox/mysql-data-transactionscope-repro
2. set REPRO_MYSQL=server=127.0.0.1;port=3306;uid=root;pwd=<password> (a user that can create and drop databases;
the program recreates a schema named ts_repro)
3. dotnet build -c Release
4. dotnet bin/Release/net10.0/TransactionScopeRepro.dll mysqldata two-connections
Also: one-connection, locked-row, and native for comparison; replace mysqldata with mysqlconnector to compare drivers.
Each run takes about 20 s with 8 concurrent workers. Expected: 0 failures, 0 hangs, 0 transactions left open (what
MySqlConnector and native transactions give). Actual with MySql.Data: ~130-200 failures, ~57-96 transactions left open,
locked-row hangs 8 of 8 workers, and the process crashed in 2 of 7 two-connections runs.