zjncs opened a new pull request, #11120:
URL: https://github.com/apache/rocketmq/pull/11120

   ## Motivation
   
   `RouteInfoManager.registerBroker` is written to tolerate a partially-filled 
`TopicConfigSerializeWrapper`: later in the method the wrapper is null-checked 
(`if (null != topicConfigWrapper ...)`), its table is null-checked (`if 
(tcTable != null)`), and the `BrokerLiveInfo` construction falls back to `new 
DataVersion()` for a null wrapper. But two earlier dereferences run before 
those guards:
   
   ```java
   long newStateVersion = 
topicConfigWrapper.getDataVersion().getStateVersion();   // version-conflict 
check
   ...
   if (!brokerAddrsMap.containsKey(brokerId) && 
topicConfigWrapper.getTopicConfigTable().size() == 1) {  // single-topic 
rejection
   ```
   
   A wrapper decoded from a malformed register body can carry explicit `null` 
fields (JSON null), so:
   
   - The version-conflict check NPEs, the catch clause aborts the registration 
**after** `clusterAddrTable`/`brokerAddrTable` were already mutated — the 
broker is left partially registered until its next heartbeat.
   - A null `getDataVersion()` that reaches the `BrokerLiveInfo` construction 
is stored into `brokerLiveTable`, and every later address-change registration 
for that broker then NPEs at `oldBrokerInfo.getDataVersion().getStateVersion()`.
   
   ## Modification
   
   - Skip the version-conflict rejection when either side's `DataVersion` is 
unavailable.
   - Skip the single-topic rejection when the wrapper or its table is null.
   - Fall back to `new DataVersion()` in the `BrokerLiveInfo` construction when 
`getDataVersion()` is null, not only when the whole wrapper is null.
   
   ## Test Evidence
   
   **Fail-before** (unpatched code, new tests):
   
   ```
   docker exec rmq-build mvn -q -pl namesrv test 
-Dtest='RouteInfoManagerTest#testRegisterBrokerWithIncompleteWrapper' 
-Dsurefire.failIfNoSpecifiedTests=true
   ERROR RocketmqNamesrv - registerBroker Exception
   java.lang.NullPointerException: ... 
TopicConfigSerializeWrapper.getDataVersion()" is null
   Tests run: 1, Failures: 1 ... Expecting actual not to be null   // 
registration aborted, no live entry for the new address
   
   docker exec rmq-build mvn -q -pl namesrv test 
-Dtest='RouteInfoManagerTest#testRegisterBrokerWithNullWrapper' 
-Dsurefire.failIfNoSpecifiedTests=true
   Tests run: 1, Failures: 1 ... Expecting actual not to be null
   ```
   
   **Pass-after** (full class with the fix — both registrations complete):
   
   ```
   docker exec rmq-build mvn -q -pl namesrv test -Dtest='RouteInfoManagerTest' 
-Dsurefire.failIfNoSpecifiedTests=true
   Tests run: 14, Failures: 0, Errors: 0, Skipped: 0
   ```
   
   No associated issue (self-discovered during a namesrv-module self-audit).


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