Skip to content

fix(lockservice): break owner-local remote lock deadlocks - #25447

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
aptend:issue25279-lockservice-deadlock-fix
Jul 4, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
aptend:issue25279-lockservice-deadlock-fix

Conversation

@aptend

@aptend aptend commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #25297
Fixes #25278
Related to #25279

What this PR does / why we need it:

This PR fixes a lockservice hang where a remote lock request can remain stuck at the lock-table owner while the origin transaction stays active and continues holding already-granted locks. In that state, existing deadlock detection may fail to break an owner-local wait cycle, and the origin-side remote lock RPC can wait for an extremely long time.

Changes:

  • Adds an owner-local deadlock fast path for remote owner-side row/exclusive waits. The owner now maintains bounded wait edges and walks only the graph rooted at the actual conflicting holders instead of scanning the whole lock table.
  • Adds an owner-side remote lock wait timeout with a dedicated ErrRemoteLockWaitTimeout, so the origin transaction is driven to rollback instead of waiting indefinitely.
  • Keeps remote lock metadata on owner-timeout so rollback can safely send remote unlock for partially granted remote lock batches.
  • Fixes deadlock detector busy enqueue bookkeeping and adds focused observability for deadlock enqueue, owner-local deadlock, and remote owner timeout paths.

Validation:

go test -v ./pkg/lockservice -count=1 -timeout=20m
PASS
ok  github.com/matrixorigin/matrixone/pkg/lockservice  580.828s

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found multiple substantive blockers here.

  1. The new owner-side remote wait cap changes user-visible lock_wait_timeout semantics.

RemoteLockOwnerWaitTimeout defaults to 2 minutes and is now always injected into remote lock requests. The effective async wait deadline then becomes the earlier of the session’s LockWaitTimeout and this owner-side cap. So a caller that explicitly configured a larger lock wait can now be aborted early at the owner’s 2-minute cap with ErrRemoteLockWaitTimeout.

That is a behavior change for valid workloads, not just protection against indefinite waits.

Suggested fix: only apply the owner-side cap when the client did not set LockWaitTimeout, or make the owner cap opt-in / disabled by default. At minimum, do not shorten an explicit caller timeout.

  1. ErrRemoteLockWaitTimeout still records a lock that was never granted.

On the owner-timeout path, remoteLockTable.lock() still executes txn.lockAdded(...) before returning ErrRemoteLockWaitTimeout. But that error means the owner timed out the waiter before grant, so the origin txn did not acquire the lock.

This leaves the origin-side held-lock set inconsistent with reality and can poison later deadlock/observability paths that walk held locks.

Suggested fix: do not call txn.lockAdded for ErrRemoteLockWaitTimeout (or remove the key before returning), and add a regression that this error leaves no new held lock on the origin txn.

  1. The owner-local fast path is applied too broadly and does O(total locks/waiters) work under the table mutex on every row/exclusive conflict.

handleLockConflictLocked() now unconditionally calls detectOwnerLocalDeadlockLocked() for qualifying row/exclusive conflicts, and that helper scans the entire local lock store and all waiters while localLockTable.mu is held.

That is a real scalability regression risk: a conflict on one row now becomes table-wide work inside the critical section, blocking unrelated lock/unlock traffic behind it.

Suggested fix: restrict this fast path to the remote-owner cases that motivated the PR, or replace the full-store scan with a bounded graph walk rooted at the actual conflicting holders/waiters.

@XuPeng-SH
XuPeng-SH merged commit 826d7ee into matrixorigin:main Jul 4, 2026
17 of 20 checks passed

This branch was previously deployed

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

Labels

kind/bug Something isn't working kind/enhancement kind/test-ci size/L Denotes a PR that changes [500,999] lines

Projects

None yet

3 participants