Skip to content

fix: remove panic on missing rangeLastWaitKey in lock conflict handler#24051

Merged
mergify[bot] merged 4 commits intomatrixorigin:mainfrom
jiangxinmeng1:fix/lock-table-remove-panic-on-missing-range-key
Apr 6, 2026
Merged

fix: remove panic on missing rangeLastWaitKey in lock conflict handler#24051
mergify[bot] merged 4 commits intomatrixorigin:mainfrom
jiangxinmeng1:fix/lock-table-remove-panic-on-missing-range-key

Conversation

@jiangxinmeng1
Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #24030

What this PR does / why we need it:

The panic "BUG: missing range last wait key" can be triggered by a legitimate race condition:

  1. txn3 acquires range lock [k1,k4], conflicts with txn1 at k4
  2. txn3 waiter is added to k4, rangeLastWaitKey set to k4
  3. txn3 blocks in wait() — releases l.mu
  4. txn1 unlocks k4: closeTxn() notifies txn3 waiter, isEmpty() returns true, k4 is deleted from store
  5. txn3 wakes, retries, conflicts at k2
  6. handleLockConflictLocked tries to clean up old k4 waiter
  7. k4 no longer exists → panic

Between step 3 (waiter blocks without lock) and step 6 (conflict retry), another transaction can legitimately delete the lock entry. The next line already guards with if ok &&, so removing the panic is safe — the waiter was already cleaned up by the unlock path.

The panic "BUG: missing range last wait key" can be triggered by a
legitimate race condition:

1. txn3 acquires range lock [k1,k4], conflicts with txn1 at k4
2. txn3 waiter is added to k4, rangeLastWaitKey set to k4
3. txn3 blocks in wait() — releases l.mu
4. txn1 unlocks k4: closeTxn() notifies txn3 waiter, isEmpty()
   returns true, k4 is deleted from store
5. txn3 wakes, retries, conflicts at k2
6. handleLockConflictLocked tries to clean up old k4 waiter
7. k4 no longer exists → panic

Between step 3 (waiter blocks without lock) and step 6 (conflict
retry), another transaction can legitimately delete the lock entry.
The next line already guards with `if ok &&`, so removing the panic
is safe — the waiter was already cleaned up by the unlock path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@qodo-code-review
Copy link
Copy Markdown

Review Summary by Qodo

Remove panic on missing rangeLastWaitKey in lock conflict handler

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Remove panic on missing rangeLastWaitKey in lock conflict handler
• Panic triggered by legitimate race condition during concurrent transactions
• Existing guard clause already handles missing lock entry safely
Diagram
flowchart LR
  A["Transaction conflict retry"] -->|rangeLastWaitKey lookup| B["Lock entry deleted by unlock"]
  B -->|Previously panicked| C["Removed panic"]
  C -->|Existing guard handles| D["Safe cleanup path"]
Loading

Grey Divider

File Changes

1. pkg/lockservice/lock_table_local.go 🐞 Bug fix +0/-3

Remove panic on missing range lock entry

• Removed panic statement that was triggered by race condition
• Lock entry can be legitimately deleted between waiter blocking and conflict retry
• Existing if ok && guard clause already safely handles missing entries

pkg/lockservice/lock_table_local.go


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown

qodo-code-review Bot commented Apr 3, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@matrix-meow matrix-meow added the size/XS Denotes a PR that changes [1, 9] lines label Apr 3, 2026
@mergify mergify Bot added the kind/bug Something isn't working label Apr 3, 2026
@matrix-meow matrix-meow added size/S Denotes a PR that changes [10,99] lines and removed size/XS Denotes a PR that changes [1, 9] lines labels Apr 3, 2026
@mergify mergify Bot added the queued label Apr 6, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Apr 6, 2026

Merge Queue Status

  • Entered queue2026-04-06 10:31 UTC · Rule: main
  • Checks passed · in-place
  • Merged2026-04-06 11:29 UTC · at 59ce38ab37bfdadf17d09dd1e671438331ad9ba1

This pull request spent 58 minutes 25 seconds in the queue, including 58 minutes 11 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage

@mergify mergify Bot merged commit 88d0757 into matrixorigin:main Apr 6, 2026
24 of 25 checks passed
@mergify mergify Bot removed the queued label Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants