Skip to content

fix(lockservice): release forwarded txn before async wait - #25469

Merged
XuPeng-SH merged 1 commit into
matrixorigin:3.0-devfrom
aptend:fix-3dev-forward-lock-waiter
Jul 6, 2026
Merged

XuPeng-SH merged 1 commit into
matrixorigin:3.0-devfrom
aptend:fix-3dev-forward-lock-waiter

Conversation

@aptend

@aptend aptend commented Jul 6, 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:

Related to #25466
Related to #25297
Related to #25278
Related to #25279

What this PR does / why we need it:

PR #25466 backported #25447 to 3.0-dev, but handleForwardLock still held the active txn mutex until the async callback.

When a forwarded lock request hits an async conflict, l.lock returns after queueing the waiter, while the callback is not called yet. Later the waiter worker retries by locking the same txn first, so it can block forever on the mutex that only the callback would release.

This PR aligns handleForwardLock with the safe ownership pattern used by handleRemoteLock: the handler releases the txn mutex with defer, and the async callback no longer owns that unlock.

It also adds a regression test that verifies a forwarded waiter resumes after the holder unlocks.

Validation:

go test ./pkg/lockservice -run 'TestForwardLockWaiterCanResumeAfterConflict|TestForwardLock|TestDeadLockWithForward|TestHandleForwardLockRejectsWhenServiceCannotLock' -count=1
ok  	github.com/matrixorigin/matrixone/pkg/lockservice	0.485s

A full package run on the same lockservice fix state also passed:

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

@aptend
aptend requested a review from iamlinjunhong as a code owner July 6, 2026 06:12
@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 did not find a blocker in this follow-up fix.

The mutex ownership change now matches the safe handleRemoteLock pattern: handleForwardLock releases the txn with defer, and the async callback no longer owns that unlock. The new regression test also covers the exact waiter-resume path that was hanging in #25466.

@XuPeng-SH
XuPeng-SH merged commit c51acef into matrixorigin:3.0-dev Jul 6, 2026
23 checks passed
XuPeng-SH added a commit that referenced this pull request Jul 17, 2026
…1-dev (#25849)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Backport of #25447 to 4.1-dev.

Fixes #25297
Fixes #25278
Related to #25279

## What this PR does / why we need it:

Backports the lockservice fix for owner-local remote lock deadlocks:

- detects owner-local wait cycles rooted at the actual conflicting
holders;
- caps owner-side remote lock waits at two minutes by default;
- retains remote lock metadata so rollback can release partially granted
locks;
- fixes deadlock detector enqueue bookkeeping and adds focused metrics;
- removes completed synchronous waiters from the deadlock-event set
before a waiter can be reused, and drops retained waiter references
during shutdown (the relevant lockservice portion of #25792).

Method_Lock is still protocol v1 and has no peer capability signal. The
owner therefore keeps the dedicated ErrRemoteLockWaitTimeout internally
but sends the existing ErrDeadLockDetected over v1. Every supported 4.1
origin recognizes that code as a whole-transaction rollback, so it
issues remote unlock even for a partial multi-row grant during a rolling
upgrade.

The cherry-pick applies cleanly to the current 4.1-dev / v4.1.2
baseline. Follow-up #25469 remains unnecessary on this branch: 4.1
already releases the forwarded transaction lock with defer txn.Unlock()
before entering the asynchronous wait path.

## Validation

- go test -v ./pkg/lockservice -count=1 -timeout=20m — PASS (573.999s)
- go build ./pkg/lockservice — PASS
- go vet ./pkg/lockservice — PASS
- focused waiter and V1 compatibility regression tests under -race
-count=10 — PASS
- go test ./pkg/frontend -run Test_isErrorRollbackWholeTxn -count=1
-timeout=5m (with repository CGO/rpath settings) — PASS

The V1 compatibility test makes a two-row remote request acquire row 1
then time out on row 2, checks the legacy deadlock code, performs the
old-origin whole-transaction unlock, and verifies row 1 is immediately
lockable.

---------

Co-authored-by: XuPeng-SH <[email protected]>

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/test-ci size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants