[Bug] Proxy:开启 namesrv的orderMessageEnable 后 broker 整组下线时 TopicRouteWrapper#getMasterAddr 空指针,导致该 topic 整条路由加载失败

Open Beginner friendly
#11,187 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java

Research direction

Start in proxy/src/main/java/org/apache/rocketmq/proxy/service/route/TopicRouteWrapper.java at getMasterAddr and inspect getMasterAddrPrefer as well. Trace how TopicRouteService.buildMessageQueueView handles a missing broker after the route cache expires. Done means an absent broker no longer causes an NPE or prevents the topic route from being built; reproduce with the orderMessageEnable and broker shutdown steps described.

Written by the indexing model from the issue text.

Description

Before Creating the Bug Report
  • I found a bug, not just asking a question, which should be created in GitHub Discussions.

  • I have searched the GitHub Issues and GitHub Discussions of this repository and believe that this is not a duplicate.

  • I have confirmed that this bug belongs to the current repository, not other repositories of RocketMQ.

Runtime platform environment

TopicRouteWrapper#getMasterAddrbrokerNameRouteData.get(brokerName) 的返回值未做判空,
直接链式调用 .getBrokerAddrs()。当某个 broker 组从 NameServer 完整注销(整组下线/单副本部署
broker 进程退出)后,brokerNameRouteData 中已无该 brokerName,get() 返回 null
随后即抛 NPE。

// 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 内判空:

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

Dominant language
Java
Stars
22.6k
Forks
12k
Avg merge
3d 12h
Merged PRs (30d)
25

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/rocketmq

All issues in apache/rocketmq

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.