Range-lock conflicts can strand waiters in stale queues A waiter that moves to a new…
- User
Range-lock conflicts can strand waiters in stale queues
A waiter that moves to a new range conflict must no longer remain in stale queues. Cleanup must preserve unrelated lock state, wake the next eligible waiter when necessary, and continue to work when the previous key disappeared or was recreated.
Interface
No new interfaces are introduced.
- Assistant
Now let me read waiter.go and waiter_events.go to understand waiter states and refs:
- Assistant
Now let me check the git diff of commit 88d075766 to see the full current cleanup logic history, then check how upstream tests are structured:
- Assistant
Now check the log.go conventions and add the log helper (or inline it). Also check whether
zapis still used in lock_table_local.go: - Assistant
The test at line 1693 expects the missing-key branch to log without crashing. I'll add the log helper to log.go following its conventions:
- Assistant
Now build and run the lockservice tests:
- Assistant
Let me look for existing tests that exercise the waiter-move behavior, and check the
beforeWait/afterWaittest seams: - Assistant
All pass. Now add regression tests covering the fixed behaviors. Let me model them on the existing unit test style:
- Assistant
Now append the regression tests at the end of lock_table_local_test.go:
- Assistant
All new tests pass. Now run the full lockservice suite:
- Assistant
Full suite passes (118s) and race-detector subset is clean. Let me review the final diff:
- Assistant
The fix is complete and verified. Summary of what was wrong and what changed:
The bug
When a range-lock retry conflicts on a different key than the previous attempt (
handleLockConflictLocked, lock_table_local.go), the old cleanup usedLock.closeWaiteron the previous key, which had three defects:- Stranded waiters —
closeWaiternever actually removesc.wfrom the previous queue unless the entire lock becomes removable. With other waiters queued behind it (or the key recreated with new holders),c.wstayed in the stale queue, and since the lock could already be holder-less, nothing would ever notify that queue again — waiters behind it hung until timeout. - Spurious self-notification — the cleanup ran after
setBlocked(c.w). Whenc.wwas still first in the old queue,closeWaiter's hand-overnotifywas delivered toc.witself (now blocking on the new key), waking its new wait with a stale value while the genuinely next waiter in the old queue was never woken. - Unrelated state disturbed — if the previous key had been deleted and recreated by another txn,
closeWaiteroperated on a lockc.wnever belonged to (potentially deleting it or notifying its first waiter prematurely).
The fix (
moveRangeConflictWaiterLocked)- Runs before
c.wis added to the new conflict queue and set to blocking —c.wis stillready, so removal can't deliver a notification the upcoming wait would consume. - Missing previous key → logged no-op (the unlock path already released the queue's reference); recreated key → membership check (
c.wmust actually be in the queue) guarantees unrelated lock state is untouched. - Removes exactly
c.wvia the existingremoveByTxnID; holders are never affected. - If the lock is holder-less and
c.wwas the designated first waiter, the next eligible waiter is notified; if the lock becomes fully empty, the entry is deleted from the store.
No new interfaces — only existing package-internal
waiterQueue/Lockmethods are used, plus a log helper in log.go following existing conventions.Verification
- 3 new unit tests: wake-next-waiter-in-stale-queue, preserve-recreated-lock, delete-empty-stale-lock — all pass.
- Existing regression tests (
TestCannotHungIfRangeConflictWithRowMultiTimes,TestHandleLockConflictLockedLogOnMissingRangeKey, allTestRangeLock*) pass. - Full
pkg/lockservicesuite passes (118s), and the range/conflict/deadlock subset is clean under-race.
- Stranded waiters —
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →