Prevent duplicate servers being added in AddPrimaryServer.

This logic was already present elsewhere and was missed in this one
place.
This commit is contained in:
Sean Chittenden
2016-06-10 15:45:54 -04:00
parent 91582dc875
commit a0902c3f45

View File

@@ -225,7 +225,12 @@ func (p *RPCProxy) AddPrimaryServer(rpcAddr string) *ServerEndpoint {
return nil
}
k := s.Key()
p.serverListLock.Lock()
if serverExists := p.primaryServers.serverExistByKey(k); serverExists {
p.serverListLock.Unlock()
return nil
}
p.primaryServers.L = append(p.primaryServers.L, s)
p.serverListLock.Unlock()
@@ -257,6 +262,18 @@ func (l *serverList) cycleServer() (servers []*ServerEndpoint) {
return newServers
}
// serverExistByKey performs a search to see if a server exists in the
// serverList. Assumes the caller is holding at least a read lock.
func (l *serverList) serverExistByKey(targetKey *EndpointKey) bool {
var found bool
for _, server := range l.L {
if targetKey.Equal(server.Key()) {
found = true
}
}
return found
}
// removeServerByKey performs an inline removal of the first matching server
func (l *serverList) removeServerByKey(targetKey *EndpointKey) {
for i, s := range l.L {