[ISSUE #10750] Fix POP lock cleanup race - #10751
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:21
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 PopConsumerLockService by replacing ConcurrentHashMapUtils.computeIfAbsent with atomic compute() in tryLock, and refactoring removeTimeout to use computeIfPresent with double-check of timeout condition.
Findings
- [Info]
PopConsumerLockService.java:42-48— Thecompute()approach ensures lock creation and acquisition are atomic. TheAtomicBooleancaptures the result from within the compute lambda. This fixes the race where a lock could be removed between creation and acquisition. - [Info]
PopConsumerLockService.java:74-89— TheremoveTimeoutrefactoring correctly re-checks the timeout insidecomputeIfPresentto handle the case where a lock was re-acquired between the iteration check and the removal attempt. - [Warning]
PopConsumerLockService.java:44— TheAtomicBoolean lockedis allocated pertryLockcall. Under high contention with many concurrent lock attempts, this creates short-lived object pressure. Consider whether a simpler return pattern is possible, though correctness is not affected. - [Info]
PopConsumerLockServiceTest.java— New testremoveTimeoutShouldNotRemoveReacquiredLockusesCountDownLatchto deterministically test the race between cleanup and re-acquisition. Good coverage.
Suggestions
- The
AtomicBooleanallocation per call is minor but worth noting for hot paths. An alternative would be to restructurecomputeto return the lock and check its state outside, but the current approach is correct and readable.
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 #10750
Brief Description
PopConsumerLockService.removeTimeout()previously made its expiration decision before removing the map entry. A concurrenttryLock()could reacquire the sameTimedLockand refresh its timestamp after that decision, but cleanup would still remove the refreshed entry and allow a second holder to be created.This change makes acquisition/refresh and the authoritative cleanup recheck atomic for each key:
tryLock()usesConcurrentHashMap.compute()to select/create and acquire the mapped lock within the per-key remapping boundary.removeTimeout()usescomputeIfPresent()to recheck the current lock timestamp before removing it.How Did You Test This Change?
develop: the deterministic latch regression failed in 5/5 isolated JDK 8 Maven processes; an independent rerun also failed 5/5.broker -am test: all 10 reactor modules passed; broker ran 753 tests with 0 failures, 0 errors, and 4 skips.git diff --check: passed.