Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

XA connection state invalid after TransactionScope.Dispose (XaEnlistedTransaction.OnRollback) on Aurora MySQL. #1590

Open
@PatrickMNL

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /