Skip to content

lockservice: remoteLockTable.unlock infinite retry on permanent errors hangs goroutines indefinitely #25202

Closed as not planned

Description

@XuPeng-SH

Summary

remoteLockTable.unlock() in lock_table_remote.go has a retry loop with no global deadline. When the remote CN returns a permanent error code not classified as needRetry=false, the unlock goroutine loops forever with exponential backoff, leaking a goroutine and never releasing the lock.

Root Cause

lock_table_remote.go:212-258:

func (l *remoteLockTable) unlock(txn *activeTxn, params UnlockParam) error {
    for {
        err, needRetry := l.doUnlock(txn, params)     // context.Background(), 10s timeout per attempt
        if err != nil {
            l.handleError(txn, err)
        }
        if !needRetry { return err }
        // exponential backoff, capped at 5s, then retry
    }
}

handleError() (line 492-506) only sets needRetry=false for:

  • ErrCodeLockBindInvalid
  • ErrCodeNotLeaseHolder
  • requestTimeout combined with bind changed

Permanent error codes that return needRetry=true:

Error code Behavior
ErrCodeCannotLockTable needRetry=true (permanent)
ErrCodeCannotAddTableLockGroup needRetry=true (permanent)
ErrLockBindConflict needRetry=true (permanent)

Impact

  • Goroutine leak: each unlock on permanent error hangs forever
  • Lock leak: active transaction locks not released on remote CN
  • Triggers during: CN rolling restart, lock table migration, allocator misconfiguration

Suggested Fix

Option 1: Add global deadline (e.g. 5 min) to unlock retry loop
Option 2: Add permanent error codes to needRetry=false list in handleError()

Related

Discovered during multi-CN transaction unhappy-path audit. See also: #25195, #25198

Activity

  1. added
    kind/bug
    severity/s0
    on Jun 29, 2026
  2. added theissue type on Jun 29, 2026
  3. added this to the MO-202607 milestone on Jun 29, 2026
  4. added
    ai-medium
    and removed
    severity/s0
    on Jul 2, 2026
  5. aptend commented on Jul 10, 2026

    @aptend
    Contributor

    Closing after re-checking this against both current main and the repository snapshot immediately before this issue was created.

    The report's central execution path does not match the code:

    • remoteLockTable.unlock/doUnlock has no needRetry return value.
    • ErrCodeCannotLockTable, ErrCodeCannotAddTableLockGroup, and ErrLockBindConflict do not exist in the repository.
    • The remote Unlock handler calls service.Unlock; an already-missing transaction returns success.
    • The retry loop handles transport/unknown-delivery failures and terminates on successful unlock or an allocator-confirmed bind change.

    This retry behavior protects a required safety invariant: when an Unlock response is lost, the caller cannot conclude that the remote lock was not acquired or released. Adding an arbitrary global deadline could therefore abandon a live remote lock.

    No code change should be made from the suggested options. Reopen or file a narrower issue if there is a reproducible Method_Unlock error that keeps the bind unchanged indefinitely; please include the exact returned error, allocator availability, and logs. Availability hardening such as service-lifecycle cancellation or background retry ownership would need a separate design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-mediumkind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions