Repository navigation
fix(lockservice): enforce lock wait timeout - #24340
LeftHandCold wants to merge 1 commit into
Conversation
ⓘ 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. |
67c19af to
9538f72
Compare
There was a problem hiding this comment.
Pull request overview
This PR enforces lock_wait_timeout during pessimistic row/table lock acquisition to prevent unbounded lock waits from keeping earlier statement locks held indefinitely in multi-statement transactions, and introduces a dedicated ErrLockWaitTimeout (MySQL 1205) that triggers whole-transaction rollback behavior.
Changes:
- Apply
lock_wait_timeoutvia a dedicated lock-acquire context and convert lock-owned deadline exceed toErrLockWaitTimeout. - Treat
ErrLockWaitTimeoutas a whole-transaction rollback error and change the defaultlock_wait_timeoutto 50s. - Add unit tests covering timeout parsing, error conversion, deadline preservation, and rollback classification.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/sql/colexec/lockop/lock_op.go | Adds lock-wait timeout context, variable resolution/parsing, and timeout error conversion to ErrLockWaitTimeout. |
| pkg/sql/colexec/lockop/lock_op_test.go | Adds unit tests for timeout parsing, context deadline preservation, and error conversion. |
| pkg/frontend/variables.go | Changes default lock_wait_timeout from 31536000s to 50s. |
| pkg/frontend/util.go | Classifies ErrLockWaitTimeout as triggering whole-transaction rollback. |
| pkg/frontend/util_test.go | Extends rollback classification tests to include ErrLockWaitTimeout. |
| pkg/common/moerr/error.go | Introduces new error code ErrLockWaitTimeout with MySQL errno 1205 message and constructors. |
| pkg/common/moerr/error_no_ctx.go | Adds NewLockWaitTimeoutNoCtx() constructor. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Apply lock_wait_timeout to pessimistic lock acquisition so a blocked lock wait cannot keep a multi-statement transaction alive indefinitely. Convert lock wait deadline expiry into a dedicated lock timeout error that rolls back the whole transaction, and align the default with MySQL's 50 seconds. Co-authored-by: Copilot <[email protected]>
9538f72 to
4a766e0
Compare
|
Closing this mitigation PR for now. Further investigation points to the root cause being in lockservice/morpc remote response write failure and caller wakeup/timeout semantics introduced around #24206, so I will replace this with a targeted root-cause fix PR. |
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 #24340 in this PR Approved by: @iamlinjunhong, @XuPeng-SH
What type of PR is this?
Which issue(s) this PR fixes:
issue #24333
What this PR does / why we need it:
Fixes a stability failure mode where a multi-statement pessimistic transaction can keep locks acquired by earlier statements while a later statement waits on another row lock indefinitely.
The root cause is that the lock wait path only observes holder notifications or the outer statement context. Although
lock_wait_timeoutexisted, it was not applied to SQL lock acquisition, and its default was effectively unbounded for stability scenarios (31536000seconds). In issue #24333 this allowed one blocked statement to keep earlier locks for nearly 20 hours, causing waiter buildup and eventually saturating CN active txn capacity.This PR:
lock_wait_timeoutto pessimistic lock acquisition inlockop, without changing the lockservice protobuf/RPC API,ErrLockWaitTimeoutusing MySQL error 1205 text,ErrLockWaitTimeoutas a whole-transaction rollback error so explicit multi-statement transactions release locks acquired by previous statements,lock_wait_timeoutto 50 seconds, matching MySQL's default and preventing effectively infinite waits,Validation