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: freetier-01 cluster (cn-dev), observed on CN pod p6bxw
Actual Behavior
When the CN leak checker detects a leaked transaction, it only logs the error and increments a counter. It does NOT clean up the transaction — no rollback, no lock release. The transaction and its held locks persist indefinitely until the frontend session disconnects.
// pkg/cnservice/server.go:770
} else {
v2.TxnLeakCounter.Inc()
runtime.DefaultRuntime().Logger().Error("found leak txn", fields...)
// No rollback, no unlock — just logging
}Observed incident
A leaked transaction d5d476fa3fed8bdc18bc8881cac4238b was created at 2026-06-28 15:09:12 on CN p6bxw (AccountID: 690440010). The leak checker detected and logged it repeatedly, but never cleaned it up. The transaction held locks for 15+ hours, blocking other CNs' transactions that needed those locks.
This triggered a cascade:
- Other CNs' waiters accumulated (4166 goroutines in
waiter.wait) checkOrphan→validTxn→GetActiveTxnRPC to p6bxw timed outfailed to valid txnerrors every 2-5 minutes for 2+ hours- Eventually: HandShake failures, connection rejections,
found leak txnon other CNs
Expected Behavior
When the leak checker identifies a transaction as leaked (no active SQL, not committing, not rolling back), it should:
- Force rollback the transaction via the txn client
- Release held locks via the lockservice
- Kill the associated session to prevent further issues
The current diagnostic-only approach allows a single leaked transaction to cascade into cluster-wide failures.
Steps to Reproduce
- Create a transaction on a CN that holds locks on shared keys.
- Make the session idle (no commit/rollback) — e.g., client disconnects without cleanup, or session gets stuck.
- Wait for the leak checker to detect it (configured interval).
- Observe: leak is logged but transaction persists, locks remain held.
- Other CNs trying to acquire the same locks will wait indefinitely.
Additional information
Related code
pkg/cnservice/server.go:740-780— leak checker detection (diagnostic only)pkg/txn/client/— txn lifecycle managementpkg/frontend/session.go— session disconnect cleanup
Log evidence
{"level":"ERROR","time":"2026/06/29 06:49:26","msg":"found leak txn",
"txn-id":"d5d476fa3fed8bdc18bc8881cac4238b",
"create-at":"2026/06/28 15:09:12"} ← 15h40m old, still not cleaned
Activity
matrix-meow commentedon Jun 30, 2026
Correction
The original description incorrectly stated that leaked transactions were idle (no SQL activity). Profile evidence shows the transactions did execute SQL and entered the lock path:
The transactions are actively trying to acquire locks on remote CNs, but the lock RPC never returns. The transaction is stuck in the lock acquisition path, not truly "leaked." The frontend session never gets a response, so there is no statement_info terminal record.
Direct code root cause for holder not releasing
pkg/lockservice/service.go:926—isValidRemoteTxn()callsisRetryError(err)onGetActiveTxntimeout, returnstruepkg/lockservice/lock_table_remote.go:385— only backend closed / cannot connect are NOT retry errors;context deadline exceededIS classified as retrypkg/lockservice/orphan_txn_test.go:807-846— tests explicitly assert this buggy behavior (validTxnerror →isValidRemoteTxn = true)See #25279 for the validTxn timeout issue.
Why GetActiveTxn keeps timing out (profile evidence)
Origin CN handler stuck at:
Code:
pkg/lockservice/service_remote.go:348,pkg/txn/client/operator.go:1533Concurrently, Commit/UpdateSnapshot/unlock paths hold
txnOperator.mu(write lock):pkg/txn/client/operator.go:716pkg/txn/client/operator.go:1021pkg/txn/client/operator.go:1426fix(lockservice): break owner-local remote lock deadlocks (matrixorig…
fix(lockservice): backport owner-local remote lock deadlock fix to 3.…
fix(lockservice): release forwarded txn before async wait (#25469)
fix(lockservice): backport owner-local remote lock deadlock fix to 4.…
fix(lockservice): break owner-local remote lock deadlocks (matrixorig…
fix(lockservice): break owner-local remote lock deadlocks (matrixorig…
fix(lockservice): break owner-local remote lock deadlocks (matrixorig…