shihaomq opened a new issue, #11187:
URL: https://github.com/apache/rocketmq/issues/11187

   ### Before Creating the Bug Report
   
   - [x] I found a bug, not just asking a question, which should be created in 
[GitHub Discussions](https://github.com/apache/rocketmq/discussions).
   
   - [x] I have searched the [GitHub 
Issues](https://github.com/apache/rocketmq/issues) and [GitHub 
Discussions](https://github.com/apache/rocketmq/discussions)  of this 
repository and believe that this is not a duplicate.
   
   - [x] I have confirmed that this bug belongs to the current repository, not 
other repositories of RocketMQ.
   
   
   ### Runtime platform environment
   
   `TopicRouteWrapper#getMasterAddr` 对 `brokerNameRouteData.get(brokerName)` 
的返回值未做判空,
   直接链式调用 `.getBrokerAddrs()`。当某个 broker 组从 NameServer 完整注销(整组下线/单副本部署
   broker 进程退出)后,`brokerNameRouteData` 中已无该 brokerName,`get()` 返回 `null`,
   随后即抛 NPE。
   
   ```java
   // 
proxy/src/main/java/org/apache/rocketmq/proxy/service/route/TopicRouteWrapper.java:45-47
   public String getMasterAddr(String brokerName) {
       return 
this.brokerNameRouteData.get(brokerName).getBrokerAddrs().get(MixAll.MASTER_ID);
       //                   ^^^^^^^^^^^^^^^^^^^^^^^^^ 整组注销后为 null,此处直接 NPE
   }
   ```
   
   ### RocketMQ version
   
   rocketmq 5.5.0
   
   ### JDK Version
   
   java 11
   
   ### Describe the Bug
   
   111
   
   ### Steps to Reproduce
   
   > 前两步即触发条件中的"开关 + KV",不可省略——省略任何一步则走动态分支,无法复现。
   
   1. namesrv 配置 `orderMessageEnable=true`;两个 broker 组(broker-a、broker-b,单副本即可);
   2. 创建 topic 并写入静态快照:
      `mqadmin updateOrderTopicKvConfig -n <ns> -t T -o "broker-a:8;broker-b:8"`
   3. 启动 proxy,经 proxy 对 T 发送若干消息(建立路由缓存);
   4. **停止使用该 topic 5 分钟以上**(让 Caffeine 条目过期),然后**整组杀掉 broker-b**;
   5. 再次经 proxy 访问 topic T(发送或查询路由)。
   
   **实测结果**(proxy 日志):
   
   ```
   java.lang.NullPointerException
       at 
org.apache.rocketmq.proxy.service.route.TopicRouteWrapper.getMasterAddr(TopicRouteWrapper.java:46)
       at 
org.apache.rocketmq.proxy.service.route.TopicRouteService.buildMessageQueueView(TopicRouteService.java:203)
       at 
org.apache.rocketmq.proxy.service.route.TopicRouteService$1.reload(TopicRouteService.java:94)
       at 
org.apache.rocketmq.proxy.service.route.TopicRouteService$1.load(TopicRouteService.java:81)
       at 
org.apache.rocketmq.proxy.service.route.MessageQueueView.<init>(MessageQueueView.java:41)
   ```
   
   broker 下线期间,T 的每次冷加载都抛 NPE,整 topic 路由不可用;broker 恢复后自愈。
   
   ### What Did You Expect to See?
   
   地址查找应空安全:brokerName 查不到时返回 null(或空 Optional),由调用方决定如何处理
   (orderTopicConf 分支至少不应让整条路由构建失败)。一个最小修复是在 `getMasterAddr` 内判空:
   
   ```java
   public String getMasterAddr(String brokerName) {
       BrokerData brokerData = this.brokerNameRouteData.get(brokerName);
       if (brokerData == null) {
           return null;
       }
       return brokerData.getBrokerAddrs().get(MixAll.MASTER_ID);
   }
   ```
   
   (`getMasterAddrPrefer` 同样的裸解引用也建议一并处理。)
   
   
   ### What Did You See Instead?
   
   111
   
   ### Additional Context
   
   _No response_


-- 
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]

Reply via email to