Support IPv6 node URLs in the cluster session#170
Merged
Conversation
Cluster node URLs were split with strings.Split(url, ":"), which mis-parses an IPv6 endpoint: "[::1]:6667" resolves to host "[" and an empty port instead of host "::1" / port "6667", while the client's own output path already brackets IPv6 via net.JoinHostPort. Parse node URLs with net.SplitHostPort via a new parseNodeURL helper, which accepts the bracketed [ipv6]:port form (consistent with apache/iotdb#18162) in addition to IPv4 and hostnames, and rejects malformed URLs with an error instead of silently mis-parsing them. Add unit tests covering IPv4, hostname, and bracketed IPv6, plus malformed inputs. Signed-off-by: Zihan Dai <99155080+PDGGK@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The cluster session parses node URLs with
strings.Split(url, ":"), reading[0]as host and[1]as port. This mis-parses an IPv6 endpoint:[::1]:6667resolves to host[and an empty port instead of host::1/ port6667. The client's own output path already brackets IPv6 vianet.JoinHostPort, so the input and output paths are inconsistent.Fix
Parse node URLs with
net.SplitHostPortvia a newparseNodeURLhelper, which accepts the bracketed[ipv6]:portform (consistent with apache/iotdb#18162) in addition to IPv4 and hostnames, and rejects malformed URLs with an error instead of silently mis-parsing them. A bare (unbracketed) IPv6 address with a port is ambiguous and rejected; the[ipv6]:portform must be used.Wildcard-address filtering (the other half of #18162) is not applicable to the Go client: it does not connect to server-provided redirect endpoints - it treats
RedirectionRecommendas success and keeps its current connection - unlike the Java/Python/C++ node-discovery and redirection paths.Tests
TestParseNodeURLcovers IPv4, hostname, and bracketed IPv6 ([::1]:6667,[2001:db8::1]:6667), plus malformed inputs (bare IPv6, missing port, unbalanced bracket, empty host/port). Parsing is unit-tested including the[::1]loopback address; a live IPv6-loopback connection test (as in #18162) would need an IPv6-capable test server, which I'm happy to add as a follow-up if the client CI supports it.go build ./...andgo test ./client/pass.Follows the dev@ "[DISCUSS] Improve IPv6 endpoint support" thread; one focused PR per client as @HTHou suggested.