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:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user