Skip to content
TheChatArchiveThe Chat Archive
GLMz-ai/glm-5.2· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION Range-lock conflicts can strand waiters in stale queues A waiter that…

  1. 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 using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to 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-$

  2. GLM Assistant

    I'll start by exploring the repository structure to understand the codebase and then investigate the range-lock issue.

  3. GLM Assistant

    This is MatrixOne, a Go-based database. The issue is about range-lock conflicts stranding waiters in stale queues. Let me find the range-lock related code.

  4. GLM Assistant

    The issue is about range-lock conflicts stranding waiters in stale queues. Let me look at the relevant files: lock_table_local.go, waiter_queue.go, waiter.go, deadlock.go.

  5. GLM Assistant

    Let me see the full file, particularly the doAcquireLock and related range lock handling:

  6. GLM Assistant

    Let me look at the closeWaiter method and the Lock struct:

  7. GLM Assistant

    Let me look at the waiter.go and waiter_events.go files:

  8. GLM Assistant

    Now let me look at the closeWaiter function more carefully and understand the bug. Let me also look at how the current test cases for range lock conflict work.

    Let me search for tests related to rangeLastWaitKey and closeWaiter.

  9. GLM Assistant

    Let me look at the git history and recent changes around this area to understand the context:

  10. GLM Assistant

    Let me search for all callers of notify/notifyAll and closeWaiter to understand the wake-up paths:

  11. GLM Assistant

    Let me look at the existing range lock tests to understand the scenarios:

  12. GLM Assistant

    This is a very detailed test. Let me see the whole scenario, particularly the part where the waiter gets stranded. Let me continue reading.

  13. GLM Assistant

    Let me run the existing range conflict test to see if it passes currently:

  14. GLM Assistant

    OK that test passes. Let me run the full lockservice test suite to see the baseline.

  15. GLM Assistant

    Let me look at the lockContext struct and how c.idx / c.offset are used:

  16. GLM Assistant

    Let me understand the doLock flow better. After wait() returns:

    • c.w.resetWait(l.logger)
    • c.offset = c.idx
    • ...

    Wait, c.offset = c.idx. But in handleLockConflictLocked, c.offset = i (for range). So after the wait, doLock RESETS c.offset = c.idx. What's c.idx?

    Let me look at how c.idx is set. In acquireRowLockLocked, c.offset = idx. There's no c.idx set there. Let me search.

  17. GLM Assistant

    Let me search the codebase for any hints about stranding or stale queues, and look at the deadlock/orphan tests which heavily exercise these paths:

  18. GLM Assistant

    All tests pass currently. Now let me deeply analyze the closeWaiter logic and the move path. Let me look at the waiter_queue_test.go and the types:

  19. GLM Assistant

    Let me check existing tests that use closeWaiter directly and understand the test for the doLock error path:

  20. GLM Assistant

    Let me check if there are any uncommitted changes or stashed content, and look at the orphan/deadlock tests which stress these paths:

  21. GLM Assistant

    Let me look at the txn.go cancel/closeBlockWaiters paths which notify waiters:

  22. GLM Assistant

    Let me check all implementations of the waiterQueue interface:

  23. GLM Assistant

    Now I have a clear understanding. Let me write a reproduction test first to confirm my understanding of the bug. Let me create a test that stresses range-lock waiter moves with multiple waiters and checks for stranded waiters:

  24. GLM Assistant

    Let me write a temporary reproduction test to confirm the bug in closeWaiter directly:

  25. GLM Assistant

    I've confirmed both bugs:

    1. Recreated empty lock wrongly deleted — closeWaiter returns true for an empty lock where w isn't even present.
    2. Non-head waiter stranded — closeWaiter leaves w in the queue when w is not the head.

    Now let me implement the fix. First, add removeWaiter to the waiter queue:

  26. GLM Assistant

    Let me make the edits using the editor. First the interface:

  27. GLM Assistant

    Now add the removeWaiter implementation. Let me view the removeByTxnID area:

  28. GLM Assistant

    Now rewrite Lock.closeWaiter in lock.go:

  29. GLM Assistant

    Now update handleLockConflictLocked to move the range cleanup BEFORE addWaiter, so the recreated+same-key case works correctly:

  30. GLM Assistant

    Let me restructure the function. I'll move the cleanup block to before addWaiter:

  31. GLM Assistant

    Let me verify the new handleLockConflictLocked order:

  32. GLM Assistant

    Now let me build and run my reproduction tests:

  33. GLM Assistant

    Both reproduction tests now pass. Let me run the broader range/deadlock related tests:

  34. GLM Assistant

    Now let me run the full lockservice test suite:

  35. GLM Assistant

    A test failed. Let me find which one:

  36. GLM Assistant

    Let me find the exact failing test name:

  37. GLM Assistant

    Two real failures. Let me look at them and run individually:

  38. GLM Assistant

    TestRowLockWithConflictAndUnlock: txn1 holds row lock. txn2 blocked by txn1 (waits). Then s.Unlock(ctx, txn2, ...) — txn2 unlocks (but it doesn't hold the lock, it's a waiter). This is supposed to abort/cancel txn2's wait. Then check that the lock still has txn2 as waiter with refcount 1 (was 3).

    Wait, let me look at the check:

    checkLock(t, lt, rows[0], [][]byte{txn1}, [][]byte{txn2}, []int32{3})
    // holders: txn1, waiters: txn2, refcounts: [3]
    
    require.NoError(t, s.Unlock(ctx, txn2, timestamp.Timestamp{}))
    <-c
    checkLock(t, lt, rows[0], [][]byte{txn1}, [][]byte{txn2}, []int32{1})
    // holders: txn1, waiters: txn2, refcounts: [1]
    

    So before unlock txn2: refcount 3. After unlock txn2: refcount 1.

    Hmm wait, refcount 3 for the waiter txn2. Let me think about the refcount. The waiter has refs from: acquireWaiter (1), queue (1), blockedWaiters (1)? = 3. After txn2 unlock (which cancels txn2's blocked waiters), the blockedWaiters ref is removed (closeBlockWaiters/closeWaiter). So refcount drops to...

    Wait, let me understand. s.Unlock(ctx, txn2, ...) — txn2 didn't hold the lock. So unlock iterates txn2's held locks (none for this table). But unlock also calls txn.close(...) which does cancelBlocks or closeBlockWaiters. Let me check.

    Actually, s.Unlock → txn.close(txnID, commitTS, ...). Let me look at txn.close.

    The test expects: after txn2 unlock, the waiter txn2 is STILL in the queue (waiters: txn2) but with refcount 1. So the waiter is NOT removed from the queue, just its refcount reduced (blockedWaiters ref removed).

    So this test RELIES on the waiter NOT being removed from the queue when txn2 is unlocked/aborted. With my change, does the closeWaiter get called and remove the waiter?

    Wait, s.Unlock(ctx, txn2, ...) for a txn that's a waiter (not holder). Let me trace. txn.close → let me look.

  39. GLM Assistant

    Let me look at checkLock and waiter_events.add to understand refcounts:

  40. GLM Assistant

    I see — TestRowLockWithConflictAndUnlock expects that when a txn aborts while waiting on a held lock (holders > 0), the waiter is NOT removed (left for lazy cleanup by the holder's release). My change removed it eagerly. The move path always has holders == 0 (the holder released to wake the waiter), so I need to preserve the "holders > 0 → don't remove" behavior and only fix the holders == 0 case.

    Let me also reconsider the restructure. With the holders guard, the cleanup-before-addWaiter move is unnecessary. Let me revert handleLockConflictLocked to the original order to minimize changes:

  41. GLM Assistant

    Now update closeWaiter to preserve the "holders > 0 → don't remove" behavior (lazy cleanup) while fixing the holders == 0 stranding:

  42. GLM Assistant

    Let me verify the removeWaiter signatures are consistent:

  43. GLM Assistant

    Both previously-failing tests now pass. Let me run the full lockservice test suite:

  44. GLM Assistant

    The full lockservice suite passes. Now let me remove my temporary reproduction test file and run a broader check to ensure nothing else depends on the changed files:

  45. GLM Assistant

    The build errors are unrelated cgo C-header issues (usearch/xxhash) — not related to my changes. The lockservice package builds fine. Let me re-run the full lockservice suite without the repro file to confirm a clean pass:

  46. GLM Assistant

    Let me re-add a comprehensive temporary test to verify all the issue's requirements, then remove it before submitting:

  47. GLM Assistant

    All requirement-based tests pass. Now let me remove the temporary test and run the relevant range/deadlock/orphan tests once more to be safe:

  48. GLM Assistant

    Let me review the final diff of my changes:

  49. GLM Assistant

    The diff is clean and minimal. Let me run the most concurrency-sensitive tests with the race detector to ensure no data races were introduced:

  50. GLM Assistant

    No data races. Let me run the full lockservice suite with the race detector to be thorough:

  51. GLM Assistant

    The entire lockservice test suite passes with the race detector enabled, no data races, no failures.

    Let me do a final review of the complete changes and confirm there are no leftover temp files:

  52. GLM Assistant

    No temp files remain. Let me do a final review of all three changed sections to ensure correctness:

  53. GLM Assistant

    Let me verify formatting with gofmt:

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.