@@ -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