From 9e9338f3e694b19108b489f5593de089dba2ed90 Mon Sep 17 00:00:00 2001 From: yomipq <158233386+yomipq@users.noreply.github.com> Date: Mon, 9 Jun 2025 09:49:37 +0900 Subject: [PATCH] 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. --- host_source.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/host_source.go b/host_source.go index adcf1a729..72cc4d79c 100644 --- a/host_source.go +++ b/host_source.go @@ -722,7 +722,21 @@ func (r *ringDescriber) GetHosts() ([]*HostInfo, string, error) { return r.prevHosts, r.prevPartitioner, err } - hosts := append([]*HostInfo{localHost}, peerHosts...) + // if the same HostID exists in peerHosts, localHost needs to be excluded to work properly with Amazon Keyspaces (CASSGO-72, #1873) + var hasSameHostID bool + for _, h := range peerHosts { + if h.HostID() == localHost.HostID() { + hasSameHostID = true + } + } + + var hosts []*HostInfo + if hasSameHostID { + hosts = peerHosts + } else { + hosts = append([]*HostInfo{localHost}, peerHosts...) + } + var partitioner string if len(hosts) > 0 { partitioner = hosts[0].Partitioner()