Skip to content

Commit ca7c56f

Browse files
committed
bugfix: fix XA rollback on commit failure (#6492)
1 parent 314b609 commit ca7c56f

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

changes/en-us/2.x.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Add changes here for all PR submitted to the 2.x branch.
3636
- [[#6385](https://github.com/apache/incubator-seata/pull/6385)] fix the bug where Role.participant does not execute hooks but clears them.
3737
- [[#6465](https://github.com/apache/incubator-seata/pull/6465)] fix(6257): fix saga mode replay context lost start in 2.x
3838
- [[#6469](https://github.com/apache/incubator-seata/pull/6469)] fix Error in insert sql of [lock_table] data table to sqlserver database
39+
- [[#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)
3940

4041
### optimize:
4142
- [[#6031](https://github.com/apache/incubator-seata/pull/6031)] add a check for the existence of the undolog table

changes/zh-cn/2.x.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
- [[#6385](https://github.com/apache/incubator-seata/pull/6385)] 修复Role.Participant不执行hook但会清理的问题
3737
- [[#6465](https://github.com/apache/incubator-seata/pull/6465)] 修复2.0下saga模式的context replay丢失start问题
3838
- [[#6469](https://github.com/apache/incubator-seata/pull/6469)] 修复在sqlserver数据库下[lock_table]数据表的插入操作sql中存在的错误
39+
- [[#6492](https://github.com/apache/incubator-seata/pull/6492)] 修复XA执行长时间SQL(或死锁SQL)没有完成回滚就释放连接
3940

4041

4142
### optimize:

rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/ConnectionProxyXA.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,13 @@ public synchronized void commit() throws SQLException {
206206
}
207207
try {
208208
// XA End: Success
209-
end(XAResource.TMSUCCESS);
209+
try {
210+
end(XAResource.TMSUCCESS);
211+
} catch (SQLException sqle) {
212+
// Rollback immediately before the XA Branch Context is deleted.
213+
rollback(false);
214+
throw new SQLException(sqle.getMessage(), SQLSTATE_XA_NOT_END, sqle);
215+
}
210216
long now = System.currentTimeMillis();
211217
checkTimeout(now);
212218
setPrepareTime(now);
@@ -224,6 +230,10 @@ public synchronized void commit() throws SQLException {
224230

225231
@Override
226232
public void rollback() throws SQLException {
233+
rollback(true);
234+
}
235+
236+
public void rollback(boolean end) throws SQLException {
227237
if (currentAutoCommitStatus) {
228238
// Ignore the committing on an autocommit session.
229239
return;
@@ -233,8 +243,10 @@ public void rollback() throws SQLException {
233243
}
234244
try {
235245
if (!rollBacked) {
236-
// XA End: Fail
237-
xaResource.end(this.xaBranchXid, XAResource.TMFAIL);
246+
if (end) {
247+
// XA End: Fail
248+
xaResource.end(this.xaBranchXid, XAResource.TMFAIL);
249+
}
238250
xaRollback(xaBranchXid);
239251
}
240252
// Branch Report to TC

0 commit comments

Comments
 (0)