This is an automated email from the ASF dual-hosted git repository. jianbin pushed a commit to branch 2.x in repository https://gitbox.apache.org/repos/asf/incubator-seata.git
The following commit(s) were added to refs/heads/2.x by this push: new c55ff6d789 bugfix: fix XA rollback on commit failure (#6492) (#6496) c55ff6d789 is described below commit c55ff6d78957b4cce40564071f07e405d1c9c00f Author: tanyaofei <tan.yao...@outlook.com> AuthorDate: Wed Apr 24 09:57:21 2024 +0800 bugfix: fix XA rollback on commit failure (#6492) (#6496) --- changes/en-us/2.x.md | 4 ++++ changes/zh-cn/2.x.md | 4 ++++ .../seata/rm/datasource/xa/ConnectionProxyXA.java | 23 +++++++++++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md index 68fd09bedb..e21557d2a8 100644 --- a/changes/en-us/2.x.md +++ b/changes/en-us/2.x.md @@ -36,8 +36,10 @@ Add changes here for all PR submitted to the 2.x branch. - [[#6385](https://github.com/apache/incubator-seata/pull/6385)] fix the bug where Role.participant does not execute hooks but clears them. - [[#6465](https://github.com/apache/incubator-seata/pull/6465)] fix(6257): fix saga mode replay context lost start in 2.x - [[#6469](https://github.com/apache/incubator-seata/pull/6469)] fix Error in insert sql of [lock_table] data table to sqlserver database +- [[#6492](https://github.com/apache/incubator-seata/pull/6492)] fix XA did not rollback but close when executing a long-running SQL(or deadlock SQL) - [[#6497](https://github.com/apache/incubator-seata/pull/6497)] fix tcc properties class when autoconfigure + ### optimize: - [[#6031](https://github.com/apache/incubator-seata/pull/6031)] add a check for the existence of the undolog table - [[#6089](https://github.com/apache/incubator-seata/pull/6089)] modify the semantics of RaftServerFactory and remove unnecessary singleton @@ -187,6 +189,8 @@ Thanks to these contributors for their code commits. Please report an unintended - [yixia](https://github.com/wt-better) - [MikhailNavitski](https://github.com/MikhailNavitski) - [deung](https://github.com/deung) +- [tanyaofei](https://github.com/tanyaofei) - [xjlgod](https://github.com/xjlgod) + Also, we receive many valuable issues, questions and advices from our community. Thanks for you all. diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md index 3382a547ed..37bdce94ff 100644 --- a/changes/zh-cn/2.x.md +++ b/changes/zh-cn/2.x.md @@ -36,8 +36,10 @@ - [[#6385](https://github.com/apache/incubator-seata/pull/6385)] 修复Role.Participant不执行hook但会清理的问题 - [[#6465](https://github.com/apache/incubator-seata/pull/6465)] 修复2.0下saga模式的context replay丢失start问题 - [[#6469](https://github.com/apache/incubator-seata/pull/6469)] 修复在sqlserver数据库下[lock_table]数据表的插入操作sql中存在的错误 +- [[#6492](https://github.com/apache/incubator-seata/pull/6492)] 修复XA执行长时间SQL(或死锁SQL)没有完成回滚就释放连接 - [[#6497](https://github.com/apache/incubator-seata/pull/6497)] 修复自动装配时的seata tcc 配置类 + ### optimize: - [[#6031](https://github.com/apache/incubator-seata/pull/6031)] 添加undo_log表的存在性校验 - [[#6089](https://github.com/apache/incubator-seata/pull/6089)] 修改RaftServerFactory语义并删除不必要的单例构建 @@ -185,6 +187,8 @@ - [yixia](https://github.com/wt-better) - [MikhailNavitski](https://github.com/MikhailNavitski) - [deung](https://github.com/deung) +- [tanyaofei](https://github.com/tanyaofei) - [xjlgod](https://github.com/xjlgod) + 同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。 diff --git a/rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/ConnectionProxyXA.java b/rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/ConnectionProxyXA.java index c983352d91..5f17b7ccc8 100644 --- a/rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/ConnectionProxyXA.java +++ b/rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/ConnectionProxyXA.java @@ -55,6 +55,8 @@ public class ConnectionProxyXA extends AbstractConnectionProxyXA implements Hold private volatile boolean xaActive = false; + private volatile boolean xaEnded = false; + private volatile boolean kept = false; private volatile boolean rollBacked = false; @@ -111,6 +113,13 @@ public class ConnectionProxyXA extends AbstractConnectionProxyXA implements Hold } } + private void xaEnd(XAXid xaXid, int flags) throws XAException { + if (!xaEnded) { + xaResource.end(xaXid, flags); + xaEnded = true; + } + } + /** * XA commit * @param xid global transaction xid @@ -206,7 +215,14 @@ public class ConnectionProxyXA extends AbstractConnectionProxyXA implements Hold } try { // XA End: Success - end(XAResource.TMSUCCESS); + try { + end(XAResource.TMSUCCESS); + } catch (SQLException sqle) { + // Rollback immediately before the XA Branch Context is deleted. + String xaBranchXid = this.xaBranchXid.toString(); + rollback(); + throw new SQLException("Branch " + xaBranchXid + " was rollbacked on committing since " + sqle.getMessage(), SQLSTATE_XA_NOT_END, sqle); + } long now = System.currentTimeMillis(); checkTimeout(now); setPrepareTime(now); @@ -234,7 +250,7 @@ public class ConnectionProxyXA extends AbstractConnectionProxyXA implements Hold try { if (!rollBacked) { // XA End: Fail - xaResource.end(this.xaBranchXid, XAResource.TMFAIL); + xaEnd(xaBranchXid, XAResource.TMFAIL); xaRollback(xaBranchXid); } // Branch Report to TC @@ -269,7 +285,7 @@ public class ConnectionProxyXA extends AbstractConnectionProxyXA implements Hold } private synchronized void end(int flags) throws XAException, SQLException { - xaResource.end(xaBranchXid, flags); + xaEnd(xaBranchXid, flags); termination(); } @@ -307,6 +323,7 @@ public class ConnectionProxyXA extends AbstractConnectionProxyXA implements Hold } // Force close the physical connection physicalConn.close(); + xaEnded = false; rollBacked = false; cleanXABranchContext(); originalConnection.close(); --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For additional commands, e-mail: notifications-h...@seata.apache.org