[ISSUE #10734] Fix broadcast offset initialization race - #10735
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 1, 2026 04:11
RockteMQ-AI
approved these changes
Aug 1, 2026
RockteMQ-AI
left a comment
Contributor
There was a problem hiding this comment.
Review by github-manager-bot
Summary
Fixes a TOCTOU race condition in BroadcastOffsetManager.queryInitOffset where a non-atomic get/create/put sequence could discard a concurrently committed broadcast offset.
Findings
- [Info]
BroadcastOffsetManager.java:88-89— Replacing the manualget/if null/putwithcomputeIfAbsentis the correct and idiomatic fix.ConcurrentHashMap.computeIfAbsentguarantees atomic initialization, preventing the race whereupdateOffsetinserts a store between thegetandput. - [Info]
BroadcastOffsetManagerConcurrencyTest.java— TheBlockingInitOffsetStoredesign is excellent. By overriding bothputandcomputeIfAbsentwithCountDownLatch-controlled blocking, the test deterministically reproduces the race without relying on sleeps or random scheduling. The test verifies:- With the old code: the race causes offset loss (test fails 5/5)
- With the fix: the offset is correctly preserved (test passes 20/20)
Suggestions
No issues found. The fix is a single-line change that eliminates the race, and the test is a model for deterministic concurrency testing.
- Correctness:
computeIfAbsentis the standard pattern for atomic get-or-create. No edge cases missed. - Performance:
computeIfAbsentis actually more efficient than the previous get+put (one atomic operation vs two). - Compatibility: Internal change only, no public API or protocol change.
LGTM.
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
Brief Description
BroadcastOffsetManager.queryInitOffsetinitializedclientOffsetStorewith a non-atomicget/ create /putsequence. IfupdateOffsetinserted and updated the same client's store between thegetandput, the query thread replaced that store and discarded the newly committed offset.Use
computeIfAbsentso initialization and concurrent updates retain the same winningBroadcastTimedOffsetStoreinstance. The change is internal and does not alter the public protocol.How Did You Test This Change?
expected 100 but was 10).validate: Checkstyle reported 0 violations across the 10 affected modules.BugInstance=0,Error=0.git diff --checksuccessfully.