From f4ab62d286ee29d67af85e727847415f75c64f94 Mon Sep 17 00:00:00 2001 From: Dhia Ayachi Date: Tue, 30 May 2023 15:31:07 -0400 Subject: [PATCH] fix isServer to exclude local address (#17519) --- agent/consul/server.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/agent/consul/server.go b/agent/consul/server.go index c7d6d19c0..418db2da1 100644 --- a/agent/consul/server.go +++ b/agent/consul/server.go @@ -1679,12 +1679,18 @@ func (s *Server) IsLeader() bool { // IsServer checks if this addr is of a server func (s *Server) IsServer(addr string) bool { - for _, s := range s.raft.GetConfiguration().Configuration().Servers { - a, err := net.ResolveTCPAddr("tcp", string(s.Address)) + + for _, ss := range s.raft.GetConfiguration().Configuration().Servers { + a, err := net.ResolveTCPAddr("tcp", string(ss.Address)) if err != nil { continue } - if string(metadata.GetIP(a)) == addr { + localIP, err := net.ResolveTCPAddr("tcp", string(s.config.RaftConfig.LocalID)) + if err != nil { + continue + } + // only return true if it's another server and not our local address + if string(metadata.GetIP(a)) == addr && string(metadata.GetIP(localIP)) != addr { return true } }