[ISSUE #10754] Fix LMQ hold request cleanup race - #10757
Open
ai-yang wants to merge 1 commit into
Open
Conversation
Signed-off-by: Rui <1685901819@qq.com>
ai-yang
marked this pull request as ready for review
August 2, 2026 14:22
RockteMQ-AI
reviewed
Aug 2, 2026
RockteMQ-AI
left a comment
Contributor
There was a problem hiding this comment.
Review by github-manager-bot
Summary
Fixes a race condition in LMQ pull request hold service cleanup and refactors PullRequestHoldService to use atomic ConcurrentHashMap.compute() operations instead of get-then-put patterns.
Findings
- [Info]
LmqPullRequestHoldService.java:57— Replacing the unsafe get-null-check-remove pattern withcomputeIfPresentis the correct fix. The original code had a TOCTOU race where a new request could be added between the emptiness check and the removal. - [Info]
PullRequestHoldService.java:48-56— TheaddPullRequesthelper usingcompute()ensures atomic bucket creation and request addition. TheConsumer<ManyPullRequest>parameter is a clean abstraction. - [Info]
PullRequestHoldService.java:180— The replay list path now also uses the sameaddPullRequesthelper, ensuring consistency. - [Info]
LmqPullRequestHoldServiceTest.java— New test file with concurrent scenario coverage usingCountDownLatchfor deterministic race testing. Good approach.
Suggestions
- The
Consumer<ManyPullRequest>allocation per call is minor but could be replaced with a method reference or lambda cached in a field if GC pressure becomes a concern under high throughput. Not blocking.
Automated review by github-manager-bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which Issue(s) This PR Fixes
Fixes #10754
Brief Description
LMQ empty-bucket cleanup previously checked
ManyPullRequest.isEmpty()and then removed the map entry in separate operations. A concurrent suspend or notification replay could append a request to the selected bucket after the empty check, while cleanup still removed that bucket frompullRequestTable. The request then remained in a detached object and could no longer be reached by message arrival or timeout scans.This change keeps bucket selection, append, and empty cleanup atomic per key:
compute()helper;computeIfPresent()and performs the authoritative synchronizedisEmpty()check inside the remapping boundary;How Did You Test This Change?
develop: the deterministic cleanup-vs-suspend regression failed in 5/5 isolated JDK 8 Maven processes.broker -am test: all 10 reactor modules passed; 2,369 tests, 9 skips, 0 failures, and 0 errors. Broker ran 755 tests, including the new class at 3/3.git diff --check: passed.