mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 19:05:42 +03:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user