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

   ### Motivation
   
   `RemotingHelper.parseHostFromAddress` splits on **every** colon and returns 
the first segment:
   
   ```java
   String[] addressSplits = address.split(":");
   return addressSplits[0];
   ```
   
   For the bracketed IPv6 form RocketMQ uses for socket addresses, this mangles 
the host:
   
   ```java
   parseHostFromAddress("[2001:db8::1]:10911")  // returns "[2001"
   ```
   
   The only caller is `BrokerPreOnlineService.waitForHaHandshakeComplete`, 
which passes the parsed value as the remote address of the 
`HAConnectionStateNotificationRequest`; 
`HAConnectionStateNotificationService.checkConnectionStateAndNotify` then 
compares it against the connection's host, so an IPv6 cluster's HA handshake 
wait can never match and pre-online times out.
   
   IPv4 addresses and bare hostnames are unaffected by the fix (first segment 
== everything before the last colon). The dead `addressSplits.length < 1` 
branch (`split` never returns an empty array) goes away with the rewrite.
   
   ### Modifications
   
   Cut at the last colon, mirroring `NetworkUtil.string2SocketAddress` and 
`NettyRemotingClient.getHostAndPort`, which already handle bracketed IPv6 this 
way.
   
   ### Verification
   
   Fail-before (new test class `RemotingHelperTest`, run against the unpatched 
code):
   
   ```
   Tests run: 1, Failures: 1 -- RemotingHelperTest#testParseHostFromAddress
   expected: "[2001:db8::1]" but was: "[2001"
   ```
   
   Pass-after:
   
   ```
   Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 -- RemotingHelperTest
   ```
   
   Note: this adds the same new test file as #11068 (`ipInCIDR`); the two PRs 
will need a trivial rebase against whichever merges first.
   


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