Skip to content

fix: wake remote lock callers on response write failure - #24345

Merged
mergify[bot] merged 8 commits into
matrixorigin:3.0-devfrom
LeftHandCold:fix-remote-lock-response-hang
May 12, 2026
Merged

mergify[bot] merged 8 commits into
matrixorigin:3.0-devfrom
LeftHandCold:fix-remote-lock-response-hang

Conversation

@LeftHandCold

@LeftHandCold LeftHandCold commented May 11, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

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

Which issue(s) this PR fixes:

fixes #24333
refs #24205

What this PR does / why we need it:

This fixes the remote lock caller hang exposed by #24333 and follows up on #24206.

#24206 correctly tightened stale remote bind handling by moving remote keepalive and orphan cleanup to bind granularity, but it also changed remote lock and forward-lock responses from AsyncWrite to bounded synchronous cs.Write. When that bounded write fails, the old path only returned the error to the handler. The peer can then stay blocked in remoteLockTable.lock -> client.Send -> Future.Get because no response is delivered and the morpc session remains open.

This PR closes the lockservice RPC client session on any response write failure. That converts a local response-write failure into a deterministic peer-side connection error, so pending futures fail and the waiting transaction follows the existing rollback and unlock path instead of holding locks indefinitely.

I intentionally do not roll back remote lock state from the write-failure path itself. After a write or flush failure, response delivery is ambiguous; unilateral unlock on the server side is riskier because the caller may still observe success and continue without a valid remote lock.

Also included:

  • richer remote lock write-failure logs with request id, method, remote endpoint, txn id, bind, caller service, and row count
  • a regression test that verifies write failure closes the session while successful writes do not
  • no lock_wait_timeout mitigation from fix(lockservice): enforce lock wait timeout #24340 in this PR

Validation

PROJECTROOT=/Users/shenjiangwei/Work/code/view/matrixone
export CGO_CFLAGS="-I$PROJECTROOT/cgo -I$PROJECTROOT/thirdparties/install/include"
export CGO_LDFLAGS="-Wl,-w,-rpath,$PROJECTROOT/thirdparties/install/lib -L$PROJECTROOT/thirdparties/install/lib -L$PROJECTROOT/cgo -lmo"
GOFLAGS=-mod=mod go test ./pkg/common/morpc ./pkg/lockservice -count=1

Close the lockservice RPC session when a bounded synchronous response write fails. A dropped response otherwise leaves the peer Future waiting indefinitely while the remote side has already processed the request.

Also log request id, method, and remote endpoint on write failures so future incidents can be correlated to the lost response.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings May 11, 2026 09:35
@qodo-code-review

Copy link
Copy Markdown
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a lockservice failure mode where a remote lock caller can hang indefinitely in Future.Get() if the server-side bounded synchronous response write fails (e.g., due to write timeout / inability to enqueue the response) but the morpc session remains open. The fix makes response-write failure deterministic for the peer by closing the RPC client session when a response write fails, ensuring pending futures fail promptly and callers can unwind/rollback.

Changes:

  • Enhance writeResponseWithDeadline error logging with request id, method, remote endpoint, and response details.
  • Close the morpc ClientSession whenever cs.Write(...) fails, to prevent peers from waiting indefinitely on a response that may never arrive.
  • Add unit coverage ensuring the session is closed on write failure and remains open on success.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pkg/lockservice/rpc.go On response write failure, logs more context and proactively closes the morpc session to wake remote waiters.
pkg/lockservice/rpc_test.go Extends the test session stub and adds a unit test verifying session closure on write error.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Capture lock RPC response metadata before handing the response to morpc. Write failures can release the response before returning, so logs must use pre-captured values.

Co-authored-by: Copilot <[email protected]>
@matrix-meow matrix-meow added size/M Denotes a PR that changes [100,499] lines and removed size/S Denotes a PR that changes [10,99] lines labels May 11, 2026

@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.

LGTM. Root-cause analysis and scope match: closing the ClientSession on write failure wakes the peer's readLoop with backendClosed, pending futures resolve, and the caller follows the existing rollback/unlock path.

Specifically good:

  • The scenario that matters is cs.Write returning DeadlineExceeded before cs.c accepts the response — the old code left the TCP session open and the peer hung in Future.Get. Close() closes cs.conn, which is exactly what the readLoop needs.
  • Commit 2's pre-capture of requestID/method/remote before cs.Write avoids the UAF that would otherwise read a released *pb.Response from the reuse pool (morpc's write path calls releaseMessage on several failure branches).
  • extraFields plumbing captures txn/bind/caller-service/row-count at handler entry so the write-failure log is still valid after the response is released.
  • Close() is idempotent via cs.mu.closed, so the redundant call on paths morpc already closes is harmless.
  • The decision not to unilaterally unlock from the write-failure path is correct — delivery is ambiguous and the peer's rollback machinery is the right driver.

Non-blocking follow-ups (worth issues, not merge blockers):

  • Scope creep is intentional and unmentioned: writeResponse now closes the session on any response-write failure (unlock, validate-service, get-active-txn, get-lock, get-waiting-list, abort-deadlock-txn, not-supported-method), not just Lock/ForwardLock. Please note in the commit message or PR body.
  • The other hang scenario — response accepted into cs.c but write loop stuck on the socket — still blocks in f.waitSendCompleted; writeCtx is not consulted past send(). Out of scope for this PR, but worth tracking.
  • At error level zap.String("response", "") is now empty when debug is off. Capturing resp.DebugString() unconditionally before cs.Write would restore the body in incident logs cheaply.
  • A direct test of "handleForwardLock hits write failure → session closed" would complete the matrix alongside the existing writeResponseWithDeadline-level close test.

@mergify

mergify Bot commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-05-12 04:58 UTC · Rule: release-3.0
  • ✅ Checks started · in-place
  • 🚫 Left the queue — 2026-05-12 05:28 UTC · at 80e1760d2b9e8503c201d15a2449ba57df1d28b6

This pull request spent 30 minutes 32 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI (3.0) / Coverage
    • check-skipped = Matrixone Utils CI (3.0) / Coverage
    • check-success = Matrixone Utils CI (3.0) / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-success = Matrixone CI (3.0) / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-success = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI (3.0) / Coverage
    • check-skipped = Matrixone Utils CI (3.0) / Coverage
    • check-success = Matrixone Utils CI (3.0) / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-success = Matrixone CI (3.0) / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-success = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)

Reason

The merge conditions cannot be satisfied due to failing checks

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

mergify Bot and others added 2 commits May 12, 2026 04:58
Copy the transaction ID before building lazy remote-lock response log fields so asynchronous write-failure logging cannot read a request after it has been returned to the reuse pool.

Also stabilize the pause-task idempotency test by waiting for the daemon task to become visible in the runner before creating the pause handler.

Co-authored-by: Copilot <[email protected]>
@mergify

mergify Bot commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-05-12 07:29 UTC · Rule: release-3.0
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-05-12 07:29 UTC · at ac337b665e66173e611d1436db71781f9805875f · squash

This pull request spent 17 seconds in the queue, including 3 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI (3.0) / Coverage
    • check-neutral = Matrixone Utils CI (3.0) / Coverage
    • check-skipped = Matrixone Utils CI (3.0) / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)

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 size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants