From 4c6ea87d23c2afc796dea11145d848cce3a92d03 Mon Sep 17 00:00:00 2001 From: Patrick le Duc Date: Wed, 20 Aug 2025 17:51:31 +0200 Subject: [PATCH] Handle a MySqlException with error code XAERRemoveFail indicating the XA state is ROLLBACK ONLY. Signed-off-by: Patrick le Duc --- src/MySqlConnector/Core/XaEnlistedTransaction.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/MySqlConnector/Core/XaEnlistedTransaction.cs b/src/MySqlConnector/Core/XaEnlistedTransaction.cs index 9f1ffe73c..496f8c566 100644 --- a/src/MySqlConnector/Core/XaEnlistedTransaction.cs +++ b/src/MySqlConnector/Core/XaEnlistedTransaction.cs @@ -32,8 +32,15 @@ protected override void OnRollback(Enlistment enlistment) { try { - if (!IsPrepared) - ExecuteXaCommand("END"); + try + { + if (!IsPrepared) + ExecuteXaCommand("END"); + } + catch (MySqlException ex) when (ex.ErrorCode is MySqlErrorCode.XAERRemoveFail && ex.Message.Contains("ROLLBACK ONLY")) + { + // ignore unprepared end failure when XAERRemoveFail is returned telling us the XA state is ROLLBACK ONLY. + } ExecuteXaCommand("ROLLBACK"); }