-
Notifications
You must be signed in to change notification settings - Fork 345
Description
Software versions
MySqlConnector version: 4.2.0
Server type (MySQL, MariaDB, Aurora, etc.) and version: AWS Aurora MySQL - 8.0.39
.NET version: 8.0
Describe the bug
After suffering from a deadlock in Aurora MySQL, the TransactionScope dispose runs in the following exception calling XA END;
MySqlConnector.MySqlException (0x80004005): XA_RBDEADLOCK: Transaction branch was rolled back: deadlock was detected
at MySqlConnector.Core.ServerSession.ReceiveReplyAsync(IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\\Projects\\Reference Packages\\MySqlConnector\\src\\MySqlConnector\\Core\\ServerSession.cs:line 1110
at MySqlConnector.Core.ResultSet.ReadResultSetHeaderAsync(IOBehavior ioBehavior) in C:\\Projects\\Reference Packages\\MySqlConnector\\src\\MySqlConnector\\Core\\ResultSet.cs:line 37
at MySqlConnector.MySqlDataReader.ActivateResultSet(CancellationToken cancellationToken) in C:\\Projects\\Reference Packages\\MySqlConnector\\src\\MySqlConnector\\MySqlDataReader.cs:line 133
at MySqlConnector.MySqlDataReader.InitAsync(CommandListPosition commandListPosition, ICommandPayloadCreator payloadCreator, IDictionary`2 cachedProcedures, IMySqlCommand command, CommandBehavior behavior, Activity activity, IOBehavior ioBehavior, CancellationToken cancellationToken) in C
:\\Projects\\Reference Packages\\MySqlConnector\\src\\MySqlConnector\\MySqlDataReader.cs:line 489
at MySqlConnector.Core.CommandExecutor.ExecuteReaderAsync(CommandListPosition commandListPosition, ICommandPayloadCreator payloadCreator, CommandBehavior behavior, Activity activity, IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\\Projects\\Reference Packages\\MySqlConnector\\src\\MySqlConnector\\Core\\CommandExecutor.cs:line 58
at MySqlConnector.MySqlCommand.ExecuteNonQueryAsync(IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\\Projects\\Reference Packages\\MySqlConnector\\src\\MySqlConnector\\MySqlCommand.cs:line 309
at MySqlConnector.MySqlCommand.ExecuteNonQuery() in C:\\Projects\\Reference Packages\\MySqlConnector\\src\\MySqlConnector\\MySqlCommand.cs:line 108
at MySqlConnector.Core.XaEnlistedTransaction.ExecuteXaCommand(String statement) in C:\\Projects\\Reference Packages\\MySqlConnector\\src\\MySqlConnector\\Core\\XaEnlistedTransaction.cs:line 50\r
\n at MySqlConnector.Core.XaEnlistedTransaction.OnRollback(Enlistment enlistment) in C:\\Projects\\Reference Packages\\MySqlConnector\\src\\MySqlConnector\\Core\\XaEnlistedTransaction.cs:line 36
While previously having introduced a try/catch for #1317 to handle this scenario when it happened on XA ROLLBACK, on this server edition, this now happens on the XA END. The exception is caught and silently ignored and XA ROLLBACK is never called. The transaction is disposed, but the XA state for the connection in Aurora has not been properly cleaned up (because of the missing XA ROLLBACK), any subsequent calls using this connection (from the pool) will be presented with the above exception.
Exception
See above.
Expected behavior
Without knowledge of the TransactionScope being disposed because of a deadlock, calling XA END still seems like the logical thing to do when the IsPrepared flag is not set, but regardless of its return calling XA ROLLBACK seems crucial to properly cleaning up the connection.
Additional context
In the PR I have opted to handle the specific scenario's known to me.