Skip to content

Commit e860bc9

Browse files
committed
Fix connection issue in Amazon Keyspaces
In Amazon Keyspaces, system.local returns the localhost address and system.peers returns a host that contains the same hostID as localhost. This causes the connection issue in refreshRing(), where host address is overwritten with the localhost address and a host with the same hostID results in the "cannot find host" error. This commit fixes GetHosts() so that it ignores localhost if the same hsotID is included in peerHosts.
1 parent c75ff5f commit e860bc9

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

host_source.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,20 @@ func (r *ringDescriber) GetHosts() ([]*HostInfo, string, error) {
722722
return r.prevHosts, r.prevPartitioner, err
723723
}
724724

725-
hosts := append([]*HostInfo{localHost}, peerHosts...)
725+
var hasSameHostID bool
726+
for _, h := range peerHosts {
727+
if h.HostID() == localHost.HostID() {
728+
hasSameHostID = true
729+
}
730+
}
731+
732+
var hosts []*HostInfo
733+
if hasSameHostID {
734+
hosts = peerHosts
735+
} else {
736+
hosts = append([]*HostInfo{localHost}, peerHosts...)
737+
}
738+
726739
var partitioner string
727740
if len(hosts) > 0 {
728741
partitioner = hosts[0].Partitioner()

0 commit comments

Comments
 (0)