Aias00 commented on issue #10892: URL: https://github.com/apache/rocketmq/issues/10892#issuecomment-5235444810
Verified on `develop` at `e3458616d207ee636b1762f0f8dcf788a590d59d` (before the proposed fix). ### Steps to reproduce 1. Populate the topic cache with exactly one entry. 2. Remove that entry after the original `isEmpty()` check but before the subsequent `iterator().next()` call. 3. Invoke candidate-topic selection. The new deterministic regression tests model this with a `ConcurrentHashMap` that clears itself during `isEmpty()`. ### Expected behavior Candidate selection should return an empty result when no entry is available, or a weakly-consistent candidate already observed by the iterator. It must not throw. ### Actual behavior The previous check-then-iterate sequence calls `iterator().next()` on an empty key set and throws `java.util.NoSuchElementException`. This can occur while a route/cache entry is concurrently evicted. ### Evidence Before the fix, `DefaultMQProducerImplTest#testPickTopicToleratesConcurrentCacheEviction` fails deterministically with `InvocationTargetException` caused by `NoSuchElementException` from `DefaultMQProducerImpl.pickTopic`. The same sequence existed in `TopicRouteService.pickTopic`. PR #10893 replaces both sequences with a single iterator plus `hasNext()` check and adds directed tests for the Java producer and Proxy route service. Local verification with JDK 8 passed: - `DefaultMQProducerImplTest`: 35 tests - `ClusterTopicRouteServiceTest` + `LocalTopicRouteServiceTest`: 7 tests -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
