Aias00 opened a new issue, #10892: URL: https://github.com/apache/rocketmq/issues/10892
### Runtime platform environment All platforms; reproduced by a deterministic unit test on the current `develop` branch. ### RocketMQ version `develop` at `e3458616d207ee636b1762f0f8dcf788a590d59d`. ### Describe the Bug Both the Java producer and Proxy availability detectors select a cached topic by first checking whether a concurrent map is empty and then creating a new iterator and immediately calling `next()`. If the final cache entry is evicted between the two operations, `next()` throws `NoSuchElementException`. The client path is `DefaultMQProducerImpl.pickTopic`; the Proxy has the same pattern in `TopicRouteService.pickTopic`. ### Steps to Reproduce 1. Populate the producer topic cache with one entry. 2. Simulate eviction immediately after `isEmpty()` returns false. 3. Invoke `pickTopic` through the availability detector helper. 4. Observe `NoSuchElementException`. ### Expected Behavior A cache that becomes empty during candidate selection returns an empty `Optional`, causing the detector to report no candidate rather than throwing. ### Actual Behavior Candidate selection throws before the detector can return a normal unavailable result. ### Proposed Fix Use one iterator and check `hasNext()` before calling `next()` in both Client and Proxy implementations. Add a regression test for the Client implementation. -- 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]
