[Bug] Proxy:开启 namesrv的orderMessageEnable 后 broker 整组下线时 TopicRouteWrapper#getMasterAddr 空指针,导致该 topic 整条路由加载失败
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
- Domain
- backend, distributed-systems
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#getMasterAddr 对 brokerNameRouteData.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",不可省略——省略任何一步则走动态分支,无法复现。
- namesrv 配置
orderMessageEnable=true;两个 broker 组(broker-a、broker-b,单副本即可); - 创建 topic 并写入静态快照:
mqadmin updateOrderTopicKvConfig -n <ns> -t T -o "broker-a:8;broker-b:8" - 启动 proxy,经 proxy 对 T 发送若干消息(建立路由缓存);
- 停止使用该 topic 5 分钟以上(让 Caffeine 条目过期),然后整组杀掉 broker-b;
- 再次经 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/rocketmq
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
[Bug] TopicValidator rejects V2 retry topic names containing `+` separator introduced by KeyBuilder Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100