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
Let me explore the repository structure to understand what we're working with.
Assistant
Let me look for range-lock related code.
Assistant
Let me see the full lock_table_local.go file, especially the doAcquireLock and related functions.
Assistant
Now let me look at the waiter.go and waiter_queue.go files.
Assistant
Assistant
Assistant
Let me look at the git history of these files to understand recent changes.
Assistant
Let me look at the existing tests around range lock conflicts and the closeWaiter function.
Assistant
Let me look at the lock_test.go for closeWaiter tests.
Assistant
Let me look at the test helpers and waiter_events.go to understand the lockContext.
Assistant
Let me write a reproduction test to demonstrate the stranding bug in
closeWaiter. First, let me understand the test setup patterns.Assistant
Let me write a reproduction test to confirm the stranding bug in
closeWaiter.Assistant
I've confirmed the bug: when a non-first waiter
w2is passed tocloseWaiter, it returnsfalseand does NOT removew2from the queue —w2remains stranded. Let me clean up the repro and design the fix.Assistant
Now let me look at the waiterQueue interface to add a
removemethod.Assistant
Now let me check if there are other implementations of the waiterQueue interface (e.g., a mock for tests).
Assistant
Now let me implement the fix. First, add a
removemethod to the waiterQueue interface and its implementation.Assistant
Now let me add the
removemethod to the interface and implementation:Assistant
Now let me rewrite the
closeWaiterfunction in lock.go.Assistant
Now I need to refine the design. The
removemethod should report both whether the waiter was found and whether it was the head, socloseWaitercan avoid touching unrelated (recreated) locks. Let me update.Assistant
Now update
closeWaiterto use the found/wasHead return:Assistant
Now let me look at the
handleLockConflictLockedcleanup and refactor it into a clear helper:Assistant
Let me refactor the cleanup into a helper method for clarity and robustness:
Assistant
I removed the
zapusage in that block. Let me check ifzapis still used elsewhere in the file:Assistant
zapis still used. Now let me build and run the relevant tests:Assistant
The fix works. Now let me write a comprehensive reproduction test to verify all the edge cases:
Assistant
All edge cases pass. Now let me run the broader lockservice test suite to ensure nothing breaks:
Assistant
There's a failure in
TestRowLockWithConflictAndUnlock. Let me see the details and check if it's pre-existing:Assistant
Let me look at the
Unlockflow and how a blocked txn's waiter is cleaned up:Assistant
So
txn.closecallstxn.cancelBlocks(logger). Let me look at cancelBlocks.Assistant
The failure is at
checkLock. Let me look at the fullcheckLockand the test flow more carefully:Assistant
The test
TestRowLockWithConflictAndUnlockencodes the OLD behavior where a stranded waiter remains in the queue after its txn aborts. My fix correctly removes it. But I need to verify refcounts are still balanced. Let me checkevents.addand the refcount flow:Assistant
Let me check whether
TestRowLockWithConflictAndUnlockwas passing before my change, by temporarily stashing my changes:Assistant
The test
TestRowLockWithConflictAndUnlockpasses on the original and breaks with my change. This is a row-lock test that encodes the existing behavior (a blocked txn that aborts leaves its waiter in the queue until the holder releases). The issue is specifically about range locks, so I should preserve the row behavior and only fix the range path.The key insight: a waiter only moves to a new conflict after being notified, which means the old lock has no holders. So I should keep the
holders > 0 → don't removeearly return (preserving the row test) while fixing the non-first removal for theholders == 0case (the range path). Let me updatecloseWaiter:Assistant
Now let me run the broader test suite to make sure nothing else breaks:
Assistant
Let me run the full lockservice test suite to be thorough:
Assistant
All lockservice tests pass. Now let me verify the original bug existed by temporarily reverting
closeWaiterand re-running my repro:Assistant
The build failed because the repro test uses
makeLockWithWaitersVetc. but the stash removed the waiter_queue.go changes too... no wait, the stash removed my changes, so the original waiter_queue.go doesn't haveremoveetc. But my repro test doesn't useremove. Let me check the build error.Assistant
Confirmed: with the original
closeWaiter, the non-first waiterw2is stranded (size=2, stranded=true). Now let me restore my fix:Assistant
Now let me re-verify the fix with my repro tests and confirm the non-first case is now fixed:
Assistant
All edge cases pass. Now let me remove the temporary repro test and run the full lockservice suite one final time to confirm:
Assistant
All tests pass. Let me review the final changes:
Assistant
Let me fix the cosmetic double blank line in waiter_queue.go:
Assistant
gofmt reports no issues. Let me run
go vetto ensure no issues (e.g., unused param concerns):Assistant
Let me reconsider the missing-key log. The previous fix (#24051) added an error log when the previous key disappeared (replacing a panic), and
TestHandleLockConflictLockedLogOnMissingRangeKeyexpects that log branch to execute. To preserve that observability and the test's intent, let me keep the log in the helper:Assistant
Let me match the original log fields exactly (including
next-conflict-key) by passing the new conflict key to the helper:Assistant
Let me view the final state of the modified
handleLockConflictLockedand helper:Assistant
Now let me run the full lockservice suite once more to confirm everything passes:
Assistant
All tests pass. Let me do a final review of the complete diff and ensure no temp files remain:
Assistant
The diff is clean. Let me also build a couple of packages that import
lockserviceto ensure no downstream breakage:Assistant
The errors are CGO header issues (usearch/xxhash) unrelated to my changes — the environment lacks those headers. Let me verify the pure-Go lockop package builds:
Assistant
The lockop package builds (exit 0); the cgo errors are environment-only (missing headers) and unrelated to my pure-Go changes. Let me double-check there are no other implementations/mocks of the
waiterQueueinterface that need the newremovemethod:Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.