[ISSUE #10750] Fix POP lock cleanup race - #10751
Conversation
RockteMQ-AI
left a comment
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
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Summary
Defensive fix with proper validation and test coverage. LGTM.
Automated review by github-manager-bot
Signed-off-by: Rui <1685901819@qq.com>
994e628 to
7cb64c7
Compare
|
Status refresh (2026-08-28):
No additional implementation changes were needed after the rebase. The issue remains actionable and this PR is not superseded by current |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #10751 +/- ##
=============================================
- Coverage 48.58% 48.49% -0.09%
+ Complexity 13676 13650 -26
=============================================
Files 1381 1381
Lines 101475 101484 +9
Branches 13190 13190
=============================================
- Hits 49299 49219 -80
- Misses 46174 46247 +73
- Partials 6002 6018 +16 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.