зеркало из https://github.com/github/vitess-gh.git
Merge pull request #40 from msolo/fix-zk-ipv6
libzookeeper_mt prior to 3.4.x doesn't handle IPv6, so prune the resolve...
This commit is contained in:
Коммит
c4d1cdf7ea
|
@ -138,3 +138,19 @@ func ResolveIpAddr(addr string) (string, error) {
|
|||
}
|
||||
return net.JoinHostPort(ipAddrs[0], port), nil
|
||||
}
|
||||
|
||||
// ResolveIpAddr resolves the address:port part into an IP address:port pair
|
||||
func ResolveIPv4Addr(addr string) (string, error) {
|
||||
host, port, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
ipAddrs, err := net.LookupIP(host)
|
||||
for _, ipAddr := range ipAddrs {
|
||||
ipv4 := ipAddr.To4()
|
||||
if ipv4 != nil {
|
||||
return net.JoinHostPort(ipv4.String(), port), nil
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("no IPv4addr for name %v", host)
|
||||
}
|
||||
|
|
|
@ -150,7 +150,8 @@ func resolveZkAddr(zkAddr string) (string, error) {
|
|||
parts := strings.Split(zkAddr, ",")
|
||||
resolved := make([]string, 0, len(parts))
|
||||
for _, part := range parts {
|
||||
if r, err := netutil.ResolveIpAddr(part); err != nil {
|
||||
// The zookeeper client cannot handle IPv6 addresses before version 3.4.x.
|
||||
if r, err := netutil.ResolveIPv4Addr(part); err != nil {
|
||||
log.Infof("cannot resolve %v, will not use it: %v", part, err)
|
||||
} else {
|
||||
resolved = append(resolved, r)
|
||||
|
|
Загрузка…
Ссылка в новой задаче