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
I'll search the codebase for range-lock conflict handling and waiter queue cleanup.
- Assistant
Running existing lockservice tests, then implementing the fix.
- Assistant
Implementing the fix: adding queue removal and updating
closeWaiter. - Assistant
Adding unit and integration tests.
- Assistant
Fixing unit tests:
notifyskips non-blocking waiters, so remaining waiters must be inblockingstate. - Assistant
Preserving original first-waiter behavior and only fixing the non-first stale-queue case.
- Assistant
Simplifying tests to focus on the core fix:
- Assistant
Fixed stale-queue stranding when a range-lock waiter moves to a new conflict.
Problem
closeWaiterreturned early when the moving waiter was not first in the queue, leaving it in the old queue afterhandleLockConflictLockedmoved it to a new conflict key.Fix
pkg/lockservice/waiter_queue.go— Addedremove(w *waiter)to drop a specific waiter and release its queue reference.pkg/lockservice/lock.go— UpdatedcloseWaiter:- Non-first waiter: always removed from the queue (the core fix)
- Holders present + non-first waiter: removed without disturbing holders or the first waiter
- First waiter: existing behavior kept (notify/skip logic for waking the next eligible waiter)
This keeps unrelated lock state intact, still wakes the next waiter when the head moves on, and still works when the previous key is missing (logged in
handleLockConflictLocked) or recreated (reload viastore.Get).Tests
Added unit tests in
lock_test.go:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.