Skip to content

[Bug]: leak checker detects leaked transactions but does not clean them up, causing indefinite lock holding #25278

Closed

Description

@matrix-meow

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

2add0b9

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:

  1. Other CNs' waiters accumulated (4166 goroutines in waiter.wait)
  2. checkOrphan → validTxn → GetActiveTxn RPC to p6bxw timed out
  3. failed to valid txn errors every 2-5 minutes for 2+ hours
  4. Eventually: HandShake failures, connection rejections, found leak txn on other CNs

Expected Behavior

When the leak checker identifies a transaction as leaked (no active SQL, not committing, not rolling back), it should:

  1. Force rollback the transaction via the txn client
  2. Release held locks via the lockservice
  3. 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

  1. Create a transaction on a CN that holds locks on shared keys.
  2. Make the session idle (no commit/rollback) — e.g., client disconnects without cleanup, or session gets stuck.
  3. Wait for the leak checker to detect it (configured interval).
  4. Observe: leak is logged but transaction persists, locks remain held.
  5. 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 management
  • pkg/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

  1. added
    kind/bug
    on Jun 30, 2026
  2. added
    severity/s0
    on Jun 30, 2026
  3. added theissue type on Jun 30, 2026
  4. added this to the MO-202607 milestone on Jun 30, 2026
  5. matrix-meow commented on Jun 30, 2026

    @matrix-meow
    ContributorAuthor

    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:

    LockOp -> remoteLockTable.lock -> lockservice.client.Send -> morpc.Future.Get
    

    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() calls isRetryError(err) on GetActiveTxn timeout, returns true
    • pkg/lockservice/lock_table_remote.go:385 — only backend closed / cannot connect are NOT retry errors; context deadline exceeded IS classified as retry
    • pkg/lockservice/orphan_txn_test.go:807-846 — tests explicitly assert this buggy behavior (validTxn error → isValidRemoteTxn = true)

    See #25279 for the validTxn timeout issue.

    Why GetActiveTxn keeps timing out (profile evidence)

    Origin CN handler stuck at:

    handleGetActiveTxn → TxnIterFunc → txnClient.IterTxns → txnOperator.GetOverview → RWMutex.RLock
    

    Code: pkg/lockservice/service_remote.go:348, pkg/txn/client/operator.go:1533

    Concurrently, Commit/UpdateSnapshot/unlock paths hold txnOperator.mu (write lock):

    • pkg/txn/client/operator.go:716
    • pkg/txn/client/operator.go:1021
    • pkg/txn/client/operator.go:1426
  6. added
    ai-heavy
    severity/s0
    and removed
    severity/s0
    on Jul 2, 2026
  7. added a commit that references this issue on Jul 4, 2026
    826d7ee
  8. added 2 commits that reference this issue on Jul 6, 2026
    9c9a178
    c51acef
  9. added a commit that references this issue on Jul 17, 2026
    e15148a
  10. added 3 commits that reference this issue on Sep 17, 2026
    c76ee82
    66815e8
    f9ded7f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-heavykind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions