Skip to content

PG数据库XA模式,GlobalTransactional默认一分钟超时后,事务发起者服务回滚失败 #6814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task
xiaoxiangyeyu0 opened this issue Sep 4, 2024 · 8 comments
Assignees
Labels
good first issue Good for newcomers task: help-wanted Extra attention is needed type: bug Category issues or prs related to bug.

Comments

@xiaoxiangyeyu0
Copy link
Contributor

  • I have searched the issues of this repository and believe that this is not a duplicate.

Ⅰ. Issue Description

org.postgresql.xa.PGXAConnection.rollback(Xid)方法
if (currentXid != null && currentXid.equals(xid))判断中的equals方法,io.seata.rm.datasource.xa.XABranchXid未重写equals方法,导致判断返回false,事务发起者连接未回滚事务,而是直接提交事务。

Ⅱ. Describe what happened

If there is an exception, please attach the exception trace:

Just paste your stack trace here!

Ⅲ. Describe what you expected to happen

Ⅳ. How to reproduce it (as minimally and precisely as possible)

  1. xxx
  2. xxx
  3. xxx

Minimal yet complete reproducer code (or URL to code):

Ⅴ. Anything else we need to know?

Ⅵ. Environment:

  • JDK version(e.g. java -version):
  • Seata client/server version: 1.5.2
  • Database version:PostgreSQL 14.10
  • OS(e.g. uname -a):
  • Others:
@funky-eyes funky-eyes added task: help-wanted Extra attention is needed good first issue Good for newcomers type: bug Category issues or prs related to bug. labels Sep 6, 2024
@funky-eyes
Copy link
Contributor

针对pg数据库,seata一阶段并不会持有该connection,二阶段下发的时候是一个新的connection,本身就不存在currentXid,你那边确定currentXid不为空吗?
For a PostgreSQL database, Seata does not hold the connection during the first phase. A new connection is used when dispatching in the second phase, so there is no currentXid involved. Can you confirm that currentXid is not null on your end?

@xiaoxiangyeyu0
Copy link
Contributor Author

事务超时会通知回滚,分布式事务发起者服务没有预提交,io.seata.rm.datasource.xa.AbstractDataSourceProxyXA.getConnectionForXAFinish(XAXid)方法如下代码会拿到待提交事务的connectionProxyXA,里面有currentXid。
String xaBranchXid = xaXid.toString();
ConnectionProxyXA connectionProxyXA = lookup(xaBranchXid);
后续
org.postgresql.xa.PGXAConnection.rollback(Xid)方法
if (currentXid != null && currentXid.equals(xid))判断中的equals方法会返回false,走了conn.setAutoCommit(true);先把事务提交了。

@funky-eyes
Copy link
Contributor

事务超时会通知回滚,分布式事务发起者服务没有预提交,io.seata.rm.datasource.xa.AbstractDataSourceProxyXA.getConnectionForXAFinish(XAXid)方法如下代码会拿到待提交事务的connectionProxyXA,里面有currentXid。 String xaBranchXid = xaXid.toString(); ConnectionProxyXA connectionProxyXA = lookup(xaBranchXid); 后续 org.postgresql.xa.PGXAConnection.rollback(Xid)方法 if (currentXid != null && currentXid.equals(xid))判断中的equals方法会返回false,走了conn.setAutoCommit(true);先把事务提交了。

你这个是超时的情况,恰好本地一阶段还没结束,所以持有了连接,我指的是二阶段没有持有连接时下发的情况。
二阶段下发时,本地没有相关连接时会new一个新的xaconnection,此时没有进start哪来的xid?

@xiaoxiangyeyu0
Copy link
Contributor Author

xiaoxiangyeyu0 commented Sep 6, 2024

是的,超时情况下,持有了连接,org.postgresql.xa.PGXAConnection.rollback(Xid)方法当前的currentXid不为null,且和入参的xid不是同一个对象,导致没有回滚。这种情况是否可以重写io.seata.rm.datasource.xa.XABranchXid的equals方法,只对比xid和branchId属性解决?

@funky-eyes
Copy link
Contributor

我认为如果是持有的connection,实际上在rollback的时候其内部成员变量的xaBranchXid是不为空的,实际上可以加一个判断,在rollback的时候,如果xaBranchXid不为空默认用成员变量这个,而不是用生成的新的xaBranchXid去触发rollback,你可以提交一个pr来修复该问题吗?

@xiaoxiangyeyu0
Copy link
Contributor Author

可以的,目前我们的1.5.2版本,io.seata.rm.datasource.xa.ConnectionProxyXA.xaRollback(String, long, String)方法重写成这样是否可以?
public synchronized void xaRollback(String xid, long branchId, String applicationData) throws XAException {
XAXid xaXid = this.xaBranchXid;
if(xaXid == null) {
xaXid = XAXidBuilder.build(xid, branchId);
}
xaRollback(xaXid);
}

@funky-eyes
Copy link
Contributor

我认为这行代码不需要,只需要直接如下即可
if(xaBranchXid !=null){
xaRollback(xaBranchXid);
}else {
.......
}

xiaoxiangyeyu0 pushed a commit to xiaoxiangyeyu0/incubator-seata that referenced this issue Sep 7, 2024
xiaoxiangyeyu0 pushed a commit to xiaoxiangyeyu0/incubator-seata that referenced this issue Sep 7, 2024
xiaoxiangyeyu0 pushed a commit to xiaoxiangyeyu0/incubator-seata that referenced this issue Sep 7, 2024
@xiaoxiangyeyu0
Copy link
Contributor Author

xiaoxiangyeyu0 commented Sep 7, 2024

pr已提交,#6825

xiaoxiangyeyu0 pushed a commit to xiaoxiangyeyu0/incubator-seata that referenced this issue Sep 7, 2024
@github-staff github-staff deleted a comment from GenaroSalomone Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers task: help-wanted Extra attention is needed type: bug Category issues or prs related to bug.
Projects
None yet
Development

No branches or pull requests

2 participants