Repository navigation
[4.2] fix(lockservice): avoid bind fence cleanup deadlock - #27569
Conversation
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 (cherry picked from commit 6798bd6)
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep-reviewed exact head 29147fadb7570318f5fbe28d25f62fb3f1c60855 against 4.2-dev.
The revised lock order is sound: the holder shard protects the pooled transaction pointer; a failed TryLock releases the shard before retrying, allowing unknown-commit cleanup (txn lock -> shard delete) to complete. A successful claim holds both protections only while inspecting/fencing transaction-owned state. Snapshotting keys does not miss a transaction with old-bind locks because lock acquisition is serialized by bindChangeMu; a transaction inserted before obtaining that read lock has not yet acquired old-bind state.
I also checked delete/reuse, rebind, waiter notification, and new-transaction interleavings. The backport's stable patch-id exactly matches the merged main fix commit. Both focused deadlock regressions pass under the deterministic CGo wrapper with -race -count=20; CI is green. No blocking design or implementation issue found.
Merge Queue Status
This pull request spent 38 seconds in the queue, including 3 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #27562
Backport of #26749 to
4.2-dev.What this PR does / why we need it:
After a TN failure produces an unknown commit,
unlockUnknownCommitcan retainactiveTxn.Lockwhile deleting the transaction from its holder shard:At the same time stale-bind fencing in the affected 4.2 code retains
shard.RLockwhile waiting for the transaction mutex:The bind-fence path also holds
bindChangeMu.Lock, so the inversion blocks every laterservice.Lockrequest atbindChangeMu.RLock. Production goroutine profiles from #27562 contain both opposing stacks for the same five-minute interval and accumulating lock requests; restarting the affected CN clears the process-local deadlock.This backport snapshots transaction keys under each holder shard, uses
TryLockwhile the shard protects the pooled transaction pointer, and releases the shard before retrying a busy transaction. This lets unknown-commit deletion finish without changing normal Lock, Unlock, Commit, allocator-fence, or proxy semantics.The cherry-pick applied cleanly to current
4.2-dev; its patch-id is identical to the merged main fix.Validation:
go build -mod=readonly ./pkg/lockservicego vet -mod=readonly ./pkg/lockservice-race -count=100pkg/lockservicetest packagepkg/lockservicetest package with-race