Skip to content

Commit 728e254

Browse files
Handle XA_RBDEADLOCK on XA END while still calling XA ROLLBACK afterwards. (#1589)
Catch XA_RBDEADLOCK on XA END seperately, still calling XA ROLLBACK afterwards to clean up the connection state. Signed-off-by: Patrick le Duc <patrick.leduc@miniclip.com> Signed-off-by: Bradley Grainger <bgrainger@gmail.com> Co-authored-by: Bradley Grainger <bgrainger@gmail.com>
1 parent 9c93fce commit 728e254

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/MySqlConnector/Core/XaEnlistedTransaction.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,25 @@ protected override void OnCommit(Enlistment enlistment)
3030

3131
protected override void OnRollback(Enlistment enlistment)
3232
{
33-
try
33+
if (!IsPrepared)
3434
{
3535
try
3636
{
37-
if (!IsPrepared)
38-
ExecuteXaCommand("END");
37+
ExecuteXaCommand("END");
3938
}
40-
catch (MySqlException ex) when (ex.ErrorCode is MySqlErrorCode.XAERRemoveFail && ex.Message.Contains("ROLLBACK ONLY"))
39+
catch (MySqlException ex) when (ex.ErrorCode is MySqlErrorCode.XARBDeadlock || (ex.ErrorCode is MySqlErrorCode.XAERRemoveFail && ex.Message.Contains("ROLLBACK ONLY")))
4140
{
42-
// ignore unprepared end failure when XAERRemoveFail is returned telling us the XA state is ROLLBACK ONLY.
41+
// ignore deadlock notification AND any unprepared end failure when XAERRemoveFail is returned telling us the XA state is ROLLBACK ONLY.
4342
}
43+
}
4444

45+
try
46+
{
4547
ExecuteXaCommand("ROLLBACK");
4648
}
4749
catch (MySqlException ex) when (ex.ErrorCode is MySqlErrorCode.XARBDeadlock)
4850
{
49-
// ignore deadlock when rolling back
51+
// ignore deadlock notification when rolling back.
5052
}
5153
}
5254

0 commit comments

Comments
 (0)