1
0
mirror of https://github.com/redis/go-redis.git synced 2025-09-07 07:47:24 +03:00

fix(client): Do not assume that all non-IP hosts are loopbacks (#3085)

* Do not assume that all non-IP hosts are loopbacks

* handle localhost and Docker internal hostnames

---------

Co-authored-by: Nedyalko Dyakov <nedyalko.dyakov@gmail.com>
Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
Co-authored-by: ofekshenawa <ofek.shenawa@redis.com>
Co-authored-by: ofekshenawa <104765379+ofekshenawa@users.noreply.github.com>
This commit is contained in:
Jonathan Suever
2025-09-02 08:58:50 -04:00
committed by GitHub
parent f0058063a9
commit 6f41b600c5
2 changed files with 50 additions and 2 deletions

View File

@@ -781,12 +781,25 @@ func replaceLoopbackHost(nodeAddr, originHost string) string {
return net.JoinHostPort(originHost, nodePort)
}
// isLoopback returns true if the host is a loopback address.
// For IP addresses, it uses net.IP.IsLoopback().
// For hostnames, it recognizes well-known loopback hostnames like "localhost"
// and Docker-specific loopback patterns like "*.docker.internal".
func isLoopback(host string) bool {
ip := net.ParseIP(host)
if ip == nil {
if ip != nil {
return ip.IsLoopback()
}
if strings.ToLower(host) == "localhost" {
return true
}
return ip.IsLoopback()
if strings.HasSuffix(strings.ToLower(host), ".docker.internal") {
return true
}
return false
}
func (c *clusterState) slotMasterNode(slot int) (*clusterNode, error) {