Repository navigation
fix(lockservice): avoid bind fence cleanup deadlock - #26749
mergify[bot] merged 2 commits into
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
iamlinjunhong
left a comment
There was a problem hiding this comment.
审查结论:APPROVE。
Findings:P0、P1、P2、P3 均无。
已核对 base 与 merge-base ffc1603,以及 head 451e272;审查了完整 4 文件 diff、bind-change 发布与 Lock 调用链、普通和 unknown-commit 删除/恢复路径、activeTxn 池化复用边界及新增回归测试。
锁序闭环成立:TryLock 失败时先释放 shard.RLock,使持有 txn.Lock 的 unknown-commit cleanup 能取得 shard.Lock 并完成删除;TryLock 成功时 shard.RLock 又能保证 pooled transaction 在访问期间不会被删除和复用。新事务若在 shard snapshot 后创建,也会被 bindChangeMu 阻挡到 bind 发布完成,再按新 bind 校验,不会漏过旧 bind fence。临时 key snapshot 按单 shard 释放,未形成无界累积。
远端 24 个 checks 均为终态且符合 watcher 门槛。隔离 worktree 的本地 CGo 测试包装器因缺少 cgo/libmo.dylib 和 third-party native artifacts 在编译前退出,因此未将该次本地尝试计为通过。
|
Queued — the merge queue status continues in this comment ↓. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed exact head 451e272e604f7a522b178a9f240be68465adc18e.
No blocking findings remain.
The deadlock root cause and the fix line up at the ownership boundary. The old bind fence held activeTxnShard.RLock while blocking on activeTxn.Lock, opposing unknown-commit cleanup's activeTxn.Lock -> activeTxnShard.Lock. The new path snapshots keys, retains the shard read lock only while validating/protecting the pooled transaction pointer, and uses TryLock; contention releases the shard before retrying. That removes the cyclic wait while preserving object-lifetime safety.
I traced the adjacent state transitions as well:
- A transaction deleted after the snapshot is observed as absent and skipped; the shard prevents deletion/reuse after the entry is selected and before the transaction lock is acquired.
- A lock request that creates a transaction while
bindChangeMuis exclusively held cannot publish an old bind: after the fence it rechecks the current table bind underbindChangeMu.RLockand either rejects the stale table or proceeds with the new one. - Unknown-commit cleanup can now acquire the shard write lock, delete the entry, finish ownership cleanup, and free the pooled transaction exactly once.
- The temporary key snapshot is bounded by one holder shard and released before visiting the next shard; the retry cost is confined to abnormal bind fencing with an already-busy transaction.
Q1/Q2/Q3 audit: one terminal owner remains for each pooled transaction; the formerly cyclic wait graph now terminates through either transaction unlock or entry deletion; no unbounded retained accumulation was introduced.
Local exact-head validation passed: the two new focused regressions under -race -count=100, full pkg/lockservice tests, go build, go vet, and git diff --check. Current GitHub CI is complete with no failures.
Merge Queue Status
This pull request spent 2 hours 21 minutes 52 seconds in the queue, including 1 hour 1 minute 36 seconds running CI. Required conditions to merge
|
The latest incident is a lockservice deadlock, not evidence that disconnected frontend sessions skipped Rollback. After unknown-commit owner cleanup succeeds, unlockUnknownCommit still holds activeTxn.Lock while deleting the transaction from its holder shard: activeTxn.Lock -> activeTxnHolder shard.Lock At the same time stale-bind cleanup used to retain shard.RLock while waiting for every transaction mutex: activeTxnHolder shard.RLock -> activeTxn.Lock The two production goroutine profiles, captured five hours apart, retain the same opposing stacks. The deadlock also holds bindChangeMu.Lock, so new lock requests accumulate behind service.Lock, making live transaction handles look like a growing txn leak. This PR: - snapshots transaction keys under each holder shard; - uses TryLock while the shard protects the pooled transaction pointer; - releases the shard and retries on contention, allowing unknown-commit deletion to complete; - preserves the existing stale-bind fence behavior once the transaction lock is acquired; - adds deterministic regression coverage for the exact unknown-cleanup/bind-fence interleaving and for the holder lock-order invariant. Normal lock, unlock, Commit, allocator-fence, and proxy handoff semantics are unchanged. The retry path is reached only during abnormal bind fencing when a transaction mutex is already busy. Validation: - pre-fix regression: deterministic timeout with unlockUnknownCommit -> deleteActiveTxn -> shard.Lock opposing fenceByBindChanged -> activeTxn.Lock; - go test -race ./pkg/lockservice -run '^(TestUnknownCommitCleanupDoesNotDeadlockBindFence|TestMapBasedTxnHolderFenceReleasesShardWhileTxnIsBusy)$' -count=100 -timeout=5m; - go test ./pkg/lockservice -count=1 -timeout=10m; - go test -race ./pkg/lockservice -count=1 -timeout=15m; - go vet ./pkg/lockservice. Approved by: @iamlinjunhong, @XuPeng-SH
The latest incident is a lockservice deadlock, not evidence that disconnected frontend sessions skipped Rollback. After unknown-commit owner cleanup succeeds, unlockUnknownCommit still holds activeTxn.Lock while deleting the transaction from its holder shard: activeTxn.Lock -> activeTxnHolder shard.Lock At the same time stale-bind cleanup used to retain shard.RLock while waiting for every transaction mutex: activeTxnHolder shard.RLock -> activeTxn.Lock The two production goroutine profiles, captured five hours apart, retain the same opposing stacks. The deadlock also holds bindChangeMu.Lock, so new lock requests accumulate behind service.Lock, making live transaction handles look like a growing txn leak. This PR: - snapshots transaction keys under each holder shard; - uses TryLock while the shard protects the pooled transaction pointer; - releases the shard and retries on contention, allowing unknown-commit deletion to complete; - preserves the existing stale-bind fence behavior once the transaction lock is acquired; - adds deterministic regression coverage for the exact unknown-cleanup/bind-fence interleaving and for the holder lock-order invariant. Normal lock, unlock, Commit, allocator-fence, and proxy handoff semantics are unchanged. The retry path is reached only during abnormal bind fencing when a transaction mutex is already busy. Validation: - pre-fix regression: deterministic timeout with unlockUnknownCommit -> deleteActiveTxn -> shard.Lock opposing fenceByBindChanged -> activeTxn.Lock; - go test -race ./pkg/lockservice -run '^(TestUnknownCommitCleanupDoesNotDeadlockBindFence|TestMapBasedTxnHolderFenceReleasesShardWhileTxnIsBusy)$' -count=100 -timeout=5m; - go test ./pkg/lockservice -count=1 -timeout=10m; - go test -race ./pkg/lockservice -count=1 -timeout=15m; - go vet ./pkg/lockservice. Approved by: @iamlinjunhong, @XuPeng-SH
The latest incident is a lockservice deadlock, not evidence that disconnected frontend sessions skipped Rollback. After unknown-commit owner cleanup succeeds, unlockUnknownCommit still holds activeTxn.Lock while deleting the transaction from its holder shard: activeTxn.Lock -> activeTxnHolder shard.Lock At the same time stale-bind cleanup used to retain shard.RLock while waiting for every transaction mutex: activeTxnHolder shard.RLock -> activeTxn.Lock The two production goroutine profiles, captured five hours apart, retain the same opposing stacks. The deadlock also holds bindChangeMu.Lock, so new lock requests accumulate behind service.Lock, making live transaction handles look like a growing txn leak. This PR: - snapshots transaction keys under each holder shard; - uses TryLock while the shard protects the pooled transaction pointer; - releases the shard and retries on contention, allowing unknown-commit deletion to complete; - preserves the existing stale-bind fence behavior once the transaction lock is acquired; - adds deterministic regression coverage for the exact unknown-cleanup/bind-fence interleaving and for the holder lock-order invariant. Normal lock, unlock, Commit, allocator-fence, and proxy handoff semantics are unchanged. The retry path is reached only during abnormal bind fencing when a transaction mutex is already busy. Validation: - pre-fix regression: deterministic timeout with unlockUnknownCommit -> deleteActiveTxn -> shard.Lock opposing fenceByBindChanged -> activeTxn.Lock; - go test -race ./pkg/lockservice -run '^(TestUnknownCommitCleanupDoesNotDeadlockBindFence|TestMapBasedTxnHolderFenceReleasesShardWhileTxnIsBusy)$' -count=100 -timeout=5m; - go test ./pkg/lockservice -count=1 -timeout=10m; - go test -race ./pkg/lockservice -count=1 -timeout=15m; - go vet ./pkg/lockservice. Approved by: @iamlinjunhong, @XuPeng-SH
What type of PR is this?
Which issue(s) this PR fixes:
issue #24766
What this PR does / why we need it:
The latest incident is a lockservice deadlock, not evidence that disconnected
frontend sessions skipped Rollback.
After unknown-commit owner cleanup succeeds, unlockUnknownCommit still holds
activeTxn.Lock while deleting the transaction from its holder shard:
At the same time stale-bind cleanup used to retain shard.RLock while waiting
for every transaction mutex:
The two production goroutine profiles, captured five hours apart, retain the
same opposing stacks. The deadlock also holds bindChangeMu.Lock, so new lock
requests accumulate behind service.Lock, making live transaction handles look
like a growing txn leak.
This PR:
to complete;
acquired;
interleaving and for the holder lock-order invariant.
Normal lock, unlock, Commit, allocator-fence, and proxy handoff semantics are
unchanged. The retry path is reached only during abnormal bind fencing when a
transaction mutex is already busy.
Validation:
unlockUnknownCommit -> deleteActiveTxn -> shard.Lock opposing
fenceByBindChanged -> activeTxn.Lock;