fix: make consumer group map thread-safe and guard NPE when no brokers - #710
Open
yyqdbngt wants to merge 1 commit into
Open
fix: make consumer group map thread-safe and guard NPE when no brokers#710yyqdbngt wants to merge 1 commit into
yyqdbngt wants to merge 1 commit into
Conversation
- consumerGroupMap is a plain HashMap read/written from request threads (queryGroupList/makeGroupListCache) and refreshAllGroup, which clears it without holding the lock; switch to ConcurrentHashMap to avoid ConcurrentModificationException and lost updates - makeGroupListCache dereferences subscriptionGroupWrapper without a null check; when the cluster has no brokers the wrapper stays null and getSubscriptionGroupTable() throws NPE, guard it and return early
yyqdbngt
force-pushed
the
fix/consumer-service-npe-and-thread-safety
branch
from
July 31, 2026 15:33
7e82fe1 to
d057cdc
Compare
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.
Motivation
Two robustness fixes in
ConsumerServiceImpl:consumerGroupMapis not thread-safeThe map is a plain
HashMapbut is read/written concurrently:queryGroupList/makeGroupListCachemutate it (on request threads), whilerefreshAllGroupcallsconsumerGroupMap.clear()without holding the same lock andrefreshGroupreads it directly. This can triggerConcurrentModificationExceptionor lost updates. Changed it to aConcurrentHashMap.NPE when the cluster has no brokers
In
makeGroupListCache,subscriptionGroupWrapperstarts asnulland is only assigned inside the per-broker loop. When the broker table is empty the wrapper staysnull, sosubscriptionGroupWrapper.getSubscriptionGroupTable()throws aNullPointerException. The empty/nullcheck is nowsubscriptionGroupWrapper == null || ...isEmpty()and returns early instead.Verification
mvn compiler:compilepasses (BUILD SUCCESS).Diff
1 file changed, +5 / -2.