fix isServer to exclude local address (#17519)

This commit is contained in:
Dhia Ayachi 2023-05-30 15:31:07 -04:00 committed by GitHub
parent d99312b86e
commit 04a0d0133a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -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
}
}