Skip to content
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

handle concurrent timeout close conn #677

Closed
wants to merge 3 commits into from
Closed

handle concurrent timeout close conn #677

wants to merge 3 commits into from

Conversation

smiletrl
Copy link
Contributor

@smiletrl smiletrl commented Mar 6, 2024

What this PR does:

pkg/database/sql/xa_resource_manager.go, xaTwoPhaseTimeoutChecker() 在xa 二阶段timeout时,(默认是1秒,https://github.com/apache/incubator-seata-go/blob/master/pkg/datasource/sql/xa_resource_manager.go#L54), 会强制关闭本地数据库conn https://github.com/apache/incubator-seata-go/blob/master/pkg/datasource/sql/xa_resource_manager.go#L105。比如我们的业务逻辑sql,执行时间超过了1秒(xa 二阶段timeout 时间)。 而原来的流程不会因为conn 已经被关闭了,就做出相应响应。而是不断地尝试Commit (正常业务逻辑sql执行完,就需要xa commit, https://github.com/apache/incubator-seata-go/blob/master/pkg/datasource/sql/conn_xa.go#L211), 然后因为commit 失败,不断尝试 Rollback。

但是此时因为原来的db conn 已经完全关闭了, https://github.com/apache/incubator-seata-go/blob/master/pkg/datasource/sql/conn_xa.go#L378,本地RM的xa 事务已经完全丢失了,xid也在数据库里找不到了,此时就不停地报错 XAER_NOTA: Unknown XID.

这个PR,在每次XA commit/rollback 前,检测下xa 状态是否还是活跃状态,在业务逻辑sql执行完成后,也检测下当前xa 状态是否还是活跃状态。

如果不是活跃状态,表示这里的db conn已经close了,或是xa tx可能已经在其他异步goroutine里 commit,或是 rollback了。那在上面的场景下,立即返回,不会重复做commit跟rollback的无用功。

Which issue(s) this PR fixes:

Fixes #676

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


@github-actions github-actions bot added the coding label Mar 6, 2024
@smiletrl smiletrl closed this by deleting the head repository May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

测试一个长时间运行的sql,timeout时,xa是否正确处理回滚遇到报错
1 participant