Hi!
When I try to connect to my Aerospike server, like this:
as.NewClient("127.0.0.1", 3000)
I get this error:
Failed to connect to host(s): [127.0.0.1:3000]
I try to set up something in /etc/hosts
such that I’m using a domain name:
as.NewClient("myserver.com", 3000)
and just get:
Failed to connect to host(s): [myserver.com:3000]
I’ve been able to track this down to the NodeValidator.setAliases
method, in particular this line:
addresses, err := net.LookupHost(host.Name)
which returns an error if the give name isn’t a domain name. Unfortunately, it appears that even when the original name is a domain, it walks up the DNS and finds an IP address and passes it to net.LookupHost
and fails because an IP address isn’t a domain name.
I’ve been able to successfully connect by making these changes:
diff --git a/node_validator.go b/node_validator.go
index dc769d1..71444c4 100644
--- a/node_validator.go
+++ b/node_validator.go
@@ -52,16 +52,23 @@ func newNodeValidator(cluster *Cluster, host *Host, timeout time.Duration) (*nod
}
func (ndv *nodeValidator) setAliases(host *Host) error {
- addresses, err := net.LookupHost(host.Name)
- if err != nil {
- return err
- }
- aliases := make([]*Host, len(addresses))
- for idx, addr := range addresses {
- aliases[idx] = NewHost(addr, host.Port)
+ ip := net.ParseIP(host.Name)
+ if ip != nil {
+ aliases := make([]*Host, 1)
+ aliases[0] = NewHost(host.Name, host.Port)
+ ndv.aliases = aliases
+ } else {
+ addresses, err := net.LookupHost(host.Name)
+ if err != nil {
+ return err
+ }
+ aliases := make([]*Host, len(addresses))
+ for idx, addr := range addresses {
+ aliases[idx] = NewHost(addr, host.Port)
+ }
+ ndv.aliases = aliases
}
- ndv.aliases = aliases
- Logger.Debug("Node Validator has %d nodes.", len(aliases))
+ Logger.Debug("Node Validator has %d nodes.", len(ndv.aliases))
return nil
}
This checks to see if the given host name is an IP address, and if it is it just uses it as its own alias rather than failing. I’m then able to connect to the cluster and read values from it.
Thoughts? Is this a bug in the client or am I doing something stupid trying to connect to it with an IP address or domain name?