Repository navigation
fix: wake remote lock callers on response write failure - #24345
mergify[bot] merged 8 commits into
Conversation
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]>
ⓘ 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. |
There was a problem hiding this comment.
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
writeResponseWithDeadlineerror logging with request id, method, remote endpoint, and response details. - Close the morpc
ClientSessionwhenevercs.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]>
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
Co-authored-by: Copilot <[email protected]>
Merge Queue Status
This pull request spent 30 minutes 32 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonThe merge conditions cannot be satisfied due to failing checks HintYou may have to fix your CI before adding the pull request to the queue again. |
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]>
Merge Queue Status
This pull request spent 17 seconds in the queue, including 3 seconds running CI. Required conditions to merge
|
What type of PR is this?
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
AsyncWriteto bounded synchronouscs.Write. When that bounded write fails, the old path only returned the error to the handler. The peer can then stay blocked inremoteLockTable.lock -> client.Send -> Future.Getbecause 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:
lock_wait_timeoutmitigation from fix(lockservice): enforce lock wait timeout #24340 in this PRValidation