[ISSUE #10892] Tolerate concurrent topic cache eviction - #10893
Conversation
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Summary
This PR fixes a real race condition in pickTopic() across both the Java producer (DefaultMQProducerImpl) and Proxy route service (TopicRouteService).
The original code had a check-then-act gap: isEmpty() returns false, but before keySet().iterator().next() executes, a concurrent cache eviction could remove the last entry, causing NoSuchElementException. The fix correctly replaces the two-step check with a single iterator: iterator.hasNext() + iterator.next(), which is safe under ConcurrentHashMap's weakly consistent iteration semantics.
Verdict: LGTM — clean, minimal, well-tested fix.
Findings
- [Info]
client/.../DefaultMQProducerImpl.java:182— TheClearingConcurrentMaptest helper is duplicated in bothDefaultMQProducerImplTestandClusterTopicRouteServiceTest. Consider extracting to a shared test utility if similar patterns emerge in the future. Minor, not blocking.
Automated review by "github-manager-bot"
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #10893 +/- ##
=============================================
- Coverage 48.60% 48.51% -0.09%
+ Complexity 13690 13655 -35
=============================================
Files 1381 1381
Lines 101464 101466 +2
Branches 13187 13189 +2
=============================================
- Hits 49318 49230 -88
- Misses 46158 46223 +65
- Partials 5988 6013 +25 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Summary
Fixes race condition in topic cache eviction by using single iterator. Good defensive fix with regression tests.
LGTM.
Automated review by github-manager-bot
Signed-off-by: liuhy <liuhongyu@apache.org>
|
Rebased onto current |
ee56179 to
e9587aa
Compare
Closes #10892.
Summary
Tests
JAVA_HOME=$(/usr/libexec/java_home -v 1.8) PATH="$JAVA_HOME/bin:$PATH" mvn -q -pl client -am -Dtest=DefaultMQProducerImplTest -DfailIfNoTests=false testJAVA_HOME=$(/usr/libexec/java_home -v 1.8) PATH="$JAVA_HOME/bin:$PATH" mvn -q -pl proxy -am -Dtest=ClusterTopicRouteServiceTest,LocalTopicRouteServiceTest -DfailIfNoTests=false test