Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
Other Environment Information
- OS type: Linux
- Others: Related to [Bug]: leak checker detects leaked transactions but does not clean them up, causing indefinite lock holding #25278
Actual Behavior
When validTxn sends a GetActiveTxn RPC to a remote CN and the RPC times out (context deadline exceeded), the error is classified as a "retry error" by isRetryError(). The isValidRemoteTxn function then conservatively assumes the transaction might still be valid and returns true, preventing lock release.
// pkg/lockservice/service.go (isValidRemoteTxn)
valid, err := h.validTxn(txn)
if err == nil {
return valid
}
logValidTxnFailed(h.logger, txn, err)
if isRetryError(err) {
return true // ← timeout = "maybe alive" = don't release locks
}
return !h.canUnlockRemoteTxn(txn)The validTxn callback uses a 10s timeout:
// pkg/lockservice/service_remote.go:109
ctx, cancel := context.WithTimeoutCause(
context.Background(), defaultRPCTimeout, // 10s
moerr.CauseInitRemote2,
)
resp, err := s.remote.client.Send(ctx, req)When the remote CN's lockservice is slow to respond (e.g., due to DN commit slowness — see #25274), the GetActiveTxn RPC consistently times out. Since context deadline exceeded is classified as a retry error, locks are never released, creating a permanent deadlock.
Observed incident
On CN p6bxw, GetActiveTxn RPCs timed out for 2+ hours because p6bxw's lockservice handlers were blocked (goroutine profile confirmed 4 goroutines stuck in handleGetActiveTxn → IterTxns → RLock blocked). Other CNs kept retrying validTxn every few minutes, always getting timeouts, never releasing locks.
07:02:23 "failed to valid txn" error="context deadline exceeded\ninternal error: initRemote 2"
07:04:53 "failed to valid txn" error="context deadline exceeded\ninternal error: initRemote 2"
07:09:53 "failed to valid txn" error="context deadline exceeded\ninternal error: initRemote 2"
... (repeated every 2-5 min for 2+ hours, same txn)
Expected Behavior
-
Consecutive timeout threshold: If
validTxnfails with timeout N consecutive times (e.g., 3-5 times), the transaction should be treated as dead and locks released. A single timeout may be transient, but repeated timeouts indicate the remote CN is genuinely unreachable. -
Separate timeout classification:
context deadline exceededfrom a 10s RPC timeout should not be treated the same as a network partition or temporary retry. Consider distinguishing:- Transient error (network blip) → retry
- Repeated timeout (remote CN overloaded) → treat as dead after threshold
- Connection refused (CN crashed) → immediately dead
-
Force unlock after max wait: If a waiter has been waiting for a lock held by a remote transaction for longer than a configurable threshold (e.g., 30 min), force release the lock regardless of validation result.
Steps to Reproduce
- Have CN-A hold locks on shared keys.
- Make CN-A's lockservice slow to respond to
GetActiveTxn(e.g., by causing DN commit slowness on CN-A). - CN-B tries to acquire the same locks, waits, triggers
checkOrphan → validTxn. GetActiveTxnRPC to CN-A times out (10s).- Observe: CN-B logs
failed to valid txnwithinitRemote 2error, locks never released. - Waiters on CN-B accumulate indefinitely.
Additional information
Related code
pkg/lockservice/service.go—isValidRemoteTxnandisRetryErrorpkg/lockservice/service_remote.go:109—validTxnwith 10s timeoutpkg/lockservice/waiter_events.go:323—checkOrphantrigger- Related: [Bug]: logservice client connects to unreachable replicas with 30s timeout, blocking DN commit pipeline #25274 (DN commit slowness causing lockservice to be slow)
- Related: [Bug]: leak checker detects leaked transactions but does not clean them up, causing indefinite lock holding #25278 (leaked txn not cleaned up — the root cause of the lock being held)
Activity
matrix-meow commentedon Jun 30, 2026
Additional: test explicitly asserts buggy behavior
pkg/lockservice/orphan_txn_test.go:807-846explicitly asserts that whenvalidTxnreturns an error (e.g.,ErrTxnNotFound),isValidRemoteTxn(...)returnstrue. This test solidifies the bug — any fix must also update this test.aptend commentedon Jul 1, 2026
After checking the incident data, I think the root cause here is not that
validTxntimed out and therefore the lock should be cleaned.The involved transactions were still active on their original CNs. Raw goroutine profiles show the transaction goroutines were blocked in the lock wait path, such as
lockservice.(*waiter).wait,remoteLockTable.lock, andlockservice.(*client).Send. In other words, the lock wait cycle kept these transactions active.So a
validTxntimeout is only a symptom/amplifier here. It means the remote CN did not answer the validation request in time, but it does not prove the transaction is orphaned or safe to unlock. If we release locks only becausevalidTxntimes out, correctness can be broken when the remote transaction is still alive and later continues or commits.The issue we should focus on is why this deadlock-like wait cycle was not detected and broken. In the raw profiles from the affected CN, the deadlock detector workers were idle in
detector.doCheck, while the transaction goroutines were stuck inwaiter.wait. This suggests the wait cycle was not effectively submitted to or processed by the detector, rather thanvalidTxnbeing the real root cause.7 remaining items
test(lockservice): stabilize lockservice flaky and hung regression te…
aptend commentedon Jul 8, 2026
follow-up pr #25509
fix(lockservice): backport owner-local remote lock deadlock fix to 4.…
fix(lockservice): break owner-local remote lock deadlocks (matrixorig…
perf(lockservice): avoid txn overview builds for active txn checks (m…
test(lockservice): stabilize lockservice flaky and hung regression te…
fix(lockservice): break owner-local remote lock deadlocks (matrixorig…
perf(lockservice): avoid txn overview builds for active txn checks (m…
test(lockservice): stabilize lockservice flaky and hung regression te…
fix(lockservice): break owner-local remote lock deadlocks (matrixorig…
perf(lockservice): avoid txn overview builds for active txn checks (m…
test(lockservice): stabilize lockservice flaky and hung regression te…