Skip to content

Commit 6e842cc

Browse files
committed
Add test for MySql.Data bug 109390.
1 parent 331902a commit 6e842cc

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

docs/content/tutorials/migrating-from-connector-net.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,5 @@ The following bugs in Connector/NET are fixed by switching to MySqlConnector. (~
297297
* [#108970](https://bugs.mysql.com/bug.php?id=108970): `MySqlConnectionStringBuilder.ContainsKey` method gives wrong result
298298
* [#109141](https://bugs.mysql.com/bug.php?id=109141): Insert of data into a table results in `System.ArgumentException`
299299
* [#109331](https://bugs.mysql.com/bug.php?id=109331): MySQL Connector/NET is incompatible with MariaDB 10.10 and later
300+
* [#109390](https://bugs.mysql.com/bug.php?id=109390): Transaction lock held after connection timeout exception
300301
* [#109476](https://bugs.mysql.com/bug.php?id=109476): `TransactionScope.Dispose` throws "Connection must be valid and open to rollback"

tests/IntegrationTests/Transaction.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,70 @@ public async Task DisposeAsync()
385385
}
386386
#endif
387387

388+
[SkippableFact(MySqlData = "https://bugs.mysql.com/bug.php?id=109390")]
389+
public void TransactionHoldsLocks()
390+
{
391+
using (var connection = new MySqlConnection(AppConfig.ConnectionString))
392+
{
393+
connection.Open();
394+
using var command = connection.CreateCommand();
395+
command.CommandText = """
396+
drop table if exists transaction_locks;
397+
create table transaction_locks(id int not null primary key, val int);
398+
insert into transaction_locks(id, val) values(1, 1);
399+
""";
400+
command.ExecuteNonQuery();
401+
}
402+
403+
using var barrier = new Barrier(2);
404+
using var barrier2 = new Barrier(2);
405+
406+
var task1 = Task.Run(() =>
407+
{
408+
using (var connection = new MySqlConnection(AppConfig.ConnectionString))
409+
{
410+
connection.Open();
411+
using var transaction = connection.BeginTransaction();
412+
using var command = connection.CreateCommand();
413+
command.CommandText = "select * from transaction_locks where id = 1 for update";
414+
command.Transaction = transaction;
415+
command.ExecuteNonQuery();
416+
barrier.SignalAndWait();
417+
barrier2.SignalAndWait();
418+
}
419+
});
420+
var task2 = Task.Run(() =>
421+
{
422+
barrier.SignalAndWait();
423+
using (var connection = new MySqlConnection(AppConfig.ConnectionString))
424+
{
425+
connection.Open();
426+
using var transaction = connection.BeginTransaction();
427+
using var command = connection.CreateCommand();
428+
command.CommandText = "update transaction_locks set val = val + 1 where id = 1";
429+
command.CommandTimeout = 3;
430+
command.Transaction = transaction;
431+
Assert.Throws<MySqlException>(() => command.ExecuteNonQuery());
432+
}
433+
barrier2.SignalAndWait();
434+
using (var connection = new MySqlConnection(AppConfig.ConnectionString))
435+
{
436+
connection.Open();
437+
using var transaction = connection.BeginTransaction();
438+
using var command = connection.CreateCommand();
439+
command.CommandText = "update transaction_locks set val = val + 1 where id = 1";
440+
command.CommandTimeout = 3;
441+
command.Transaction = transaction;
442+
command.ExecuteNonQuery();
443+
transaction.Commit();
444+
}
445+
});
446+
447+
task1.GetAwaiter().GetResult();
448+
Assert.Equal(0, Task.WaitAny(task2, Task.Delay(TimeSpan.FromSeconds(10))));
449+
task2.GetAwaiter().GetResult();
450+
}
451+
388452
readonly TransactionFixture m_database;
389453
readonly MySqlConnection m_connection;
390454
}

0 commit comments

Comments
 (0)