[ISSUE #10591] Fix IPv6 NPE in NetworkUtil.string2SocketAddress by stripping brackets#10592
[ISSUE #10591] Fix IPv6 NPE in NetworkUtil.string2SocketAddress by stripping brackets#10592itxaiohanglover wants to merge 3 commits into
Conversation
…g brackets When a gRPC client connects via IPv6, the remote address is formatted as [240e:...:2]:44880. The string2SocketAddress method splits on the last colon, leaving the host part with surrounding brackets. Java's InetSocketAddress constructor fails to resolve the bracketed host, causing getAddress() to return null, which triggers a NullPointerException in CommitLog.asyncPutMessage. Strip the surrounding [] before constructing InetSocketAddress.
|
Thanks for the fix. Could you also check |
As noted in PR review, SimpleChannel#parseSocketAddress used
address.split(":") which fails for IPv6 addresses like
[240e:...:2]:44880 — split produces more than 2 segments so the
method returns null, causing bornSocketAddress to be null and
triggering the NPE in CommitLog.
Use lastIndexOf(":") to split host:port and strip brackets from
IPv6 host, consistent with the NetworkUtil.string2SocketAddress fix.
|
Thanks for pointing that out! You're right — Fixed in the latest push — switched to |
yx9o
left a comment
There was a problem hiding this comment.
Thanks for the update. It would be better to add a unit test for the SimpleChannel change.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #10592 +/- ##
=============================================
- Coverage 48.26% 48.17% -0.10%
+ Complexity 13433 13410 -23
=============================================
Files 1378 1378
Lines 100817 100823 +6
Branches 13040 13042 +2
=============================================
- Hits 48660 48569 -91
- Misses 46211 46295 +84
- Partials 5946 5959 +13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Cover IPv4, IPv6 with brackets, IPv6 loopback, null/empty input, and missing port cases to improve patch coverage.
Which Issue(s) This PR Fixes
Fixes #10591
Brief Description
When a gRPC client connects to the Proxy via IPv6, the remote address is formatted as
[240e:...:2]:44880(with brackets). TheNetworkUtil.string2SocketAddressmethod splits on the last:to separate host and port, but the host part retains the surrounding[]brackets.When
new InetSocketAddress("[240e:...:2]", port)is constructed with a bracketed host, Java'sInetAddress.getByName()fails to resolve it, causinggetAddress()to returnnull. Thisnullpropagates toCommitLog.asyncPutMessage(line 994) wherebornSocketAddress.getAddress()triggers aNullPointerException.Root cause:
string2SocketAddressdoes not strip IPv6 brackets before constructingInetSocketAddress.Fix: Strip surrounding
[]from the host part before callingnew InetSocketAddress(host, port).How Did You Test This Change?
Added
NetworkUtilTestwith 5 test cases:testString2SocketAddressIPv4— existing IPv4 behavior unchangedtestString2SocketAddressIPv6WithBrackets— reproduces the issue:[240e:341:6246:c700:c4ad:e645:459e:2]:44880now resolves correctly with non-nullgetAddress()testString2SocketAddressIPv6Loopback—[::1]:8080resolves correctlytestSocketAddress2StringIPv4— round-trip conversion unchangedtestNormalizeAndDenormalizeHostAddress— bracket normalize/denormalize helpers