handle concurrent timeout close conn #677
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?: