Skip to content

[ISSUE #10892] Tolerate concurrent topic cache eviction - #10893

Open
Aias00 wants to merge 1 commit into
apache:developfrom
Aias00:test/topic-cache-candidate-race
Open

[ISSUE #10892] Tolerate concurrent topic cache eviction#10893
Aias00 wants to merge 1 commit into
apache:developfrom
Aias00:test/topic-cache-candidate-race

Conversation

@Aias00

@Aias00 Aias00 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Closes #10892.

Summary

  • select a candidate topic through a single iterator in both the Java producer and Proxy route service
  • avoid the check-then-iterate race when concurrent cache eviction removes the final entry
  • add deterministic regression tests for both affected paths

Tests

  • JAVA_HOME=$(/usr/libexec/java_home -v 1.8) PATH="$JAVA_HOME/bin:$PATH" mvn -q -pl client -am -Dtest=DefaultMQProducerImplTest -DfailIfNoTests=false test
  • JAVA_HOME=$(/usr/libexec/java_home -v 1.8) PATH="$JAVA_HOME/bin:$PATH" mvn -q -pl proxy -am -Dtest=ClusterTopicRouteServiceTest,LocalTopicRouteServiceTest -DfailIfNoTests=false test

Copilot AI lite review requested due to automatic review settings August 10, 2026 03:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 — The ClearingConcurrentMap test helper is duplicated in both DefaultMQProducerImplTest and ClusterTopicRouteServiceTest. Consider extracting to a shared test utility if similar patterns emerge in the future. Minor, not blocking.

Automated review by "github-manager-bot"

@codecov-commenter

codecov-commenter commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.51%. Comparing base (293f588) to head (e9587aa).

Files with missing lines Patch % Lines
...mq/client/impl/producer/DefaultMQProducerImpl.java 66.66% 0 Missing and 1 partial ⚠️
...ocketmq/proxy/service/route/TopicRouteService.java 66.66% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@Aias00

Aias00 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current develop and revalidated DefaultMQProducerImplTest plus ClusterTopicRouteServiceTest. The previous Bazel failure was PopPriorityIT, an unrelated integration test; the branch update will trigger a fresh CI run.

@Aias00
Aias00 force-pushed the test/topic-cache-candidate-race branch from ee56179 to e9587aa Compare August 14, 2026 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Topic candidate selection races with concurrent cache eviction

4 participants