ISSUE DESCRIPTION Range-lock conflicts can strand waiters in stale queues A waiter that…
- User
ISSUE DESCRIPTION
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.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /matrixone, current file: none) bash-$
Assistant
Now let's add the
removemethod to the interface and implementation.Assistant
Now let's add the implementation after
removeByTxnID:Assistant
Now let's build to check for compile errors, and check other call sites use the right signature.
Assistant
Build succeeds. Now let's run the existing tests in this package.
Assistant
Now let's remove the debug prints and rerun tests.
Assistant
No DEBUG left (grep found nothing → exit 1, expected). Let's check the file content is correct.
Assistant
Now remove the debug print from lock.go's closeWaiter.
Assistant
Fixed. Now let's run the full lockservice test suite multiple times to check for other flakiness introduced.
Assistant
Let's find which test failed.
Assistant
Let's refine the
closeWaiterimplementation to preserve the holders>0 early-return behavior (required by existing test), while fixing the removal/notify bug for the holders==0 case.Assistant
Both pass now. Let's also check the second failing test
TestBindChangedFencesActiveTxnHoldingOldBindfor flakiness against baseline.Assistant
Now let's run the full lockservice suite multiple times to be confident.
Assistant
Good, two full runs passed cleanly. Let's run a third individually.
Assistant
All three full runs pass. Now let's run with
-raceto catch any data races introduced.Assistant
Now let's write a small targeted reproduction test (temporary, not committed) simulating the exact scenario from the issue (waiter moving across multiple different range conflicts with other waiters queued behind) to confirm the fix handles it, then remove the temp file.
Assistant
All three scenarios verified correct behavior. Now let's verify that WITHOUT my fix (old code), this test would fail, confirming it truly exercises the bug.
Assistant
Good, fix restored. Now let's clean up the temp file (already removed) and re-verify everything builds/tests pass.
Assistant
Good, temp test file removed and only the intended source changes remain. Now let's view the final diff.
Assistant
Now let's find any other packages depending on lockservice that might use
Lock.closeWaiterorwaiterQueuedirectly, to ensure no breakage.Assistant
No external usages (exit 123 just means grep found nothing, since these are unexported). Let's run the entire lockservice test suite once more (final check) plus race detection on the range/waiter related tests.
Assistant
All good. Let's view the final diff once more for a clean review.
Assistant
This looks solid. Let's do one more full-suite run to be extra confident, plus run the broader
lockserviceand any dependent package tests (e.g.,pkg/frontendor others that might exercise lock behavior) briefly — but given scope, let's check for other packages importing lockservice types likeLockdirectly.Assistant
No external usages. The change is fully contained within
pkg/lockservice. Let's do a final full test run.Assistant
All tests pass. Let's review the checklist explicitly.
Assistant
I've completed a thorough analysis and fix for this issue. Let me summarize the work done and go through the checklist:
Summary
The bug was in
Lock.closeWaiter()inpkg/lockservice/lock.go, used byhandleLockConflictLocked()inlock_table_local.goto clean up a waiter that moved from an old range-lock conflict key to a new one.Root causes found:
closeWaiteronly removed the waiter from the queue when it happened to be alone (waiters.size()==1) and first. In every other case (not first, or first with siblings behind it) it returnedfalsewithout removingwfrom the queue at all, silently stranding it there forever.- Worse, when the waiter was first with other waiters behind it, it called
l.waiters.notify(...)before removing itself — since the waiter's status was alreadyblocking(for its new key),notify()would incorrectly re-notify/consume itself instead of waking the next legitimate waiter, starving that waiter forever and risking a channel-send panic when the real notification for the new key arrived later. handleLockConflictLockedunconditionally tried to clean upc.rangeLastWaitKeyeven when the new conflict key was identical to the last one (a legitimate re-conflict on the same key across retries), which could rip the waiter out of the very entry it had just been added to.
Fixes:
- Added a proper
waiterQueue.remove(w)that removes a specific waiter by identity (not by position/txnID) and releases its ref without notifying it. - Rewrote
closeWaiterto: preserve holder state untouched (matching existing test expectations), always removewwhen there are no holders regardless of position, and only wake the next waiter whenwwas actually the head. - Guarded the stale-key cleanup with a same-key check so re-conflicting on the same key is a no-op.
I verified this with a temporary repro test (removed before submission) that reproduced the hang with the old code and passed with the fix, then ran the full
pkg/lockservicesuite repeatedly (including-race) with no failures.Checklist
- Reproduced the issue: Yes — via targeted repro scenarios showing waiters stranded/incorrectly notified with the old code (confirmed hang), and via discovering
TestRangeLockWithWaitQueueflakiness while iterating on the fix. - Confirmed the fix resolves it: Yes — repro scenarios pass, and 3+ full test-suite runs (plus
-raceruns) pass consistently. - Edge cases considered: holders present (preserve state), waiter not at head, waiter at head with/without siblings, key disappeared, key recreated/same-key re-conflict, empty queue.
- Existing tests pass: Yes, full
pkg/lockservicesuite passes repeatedly, including previously-flaky/borderline tests.
Assistant
This is my final solution. Let's submit it.
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
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →