Skip to content

Commit

Permalink
Prevent duplicate servers being added in AddPrimaryServer.
Browse files Browse the repository at this point in the history
This logic was already present elsewhere and was missed in this one
place.
  • Loading branch information
sean- committed Jun 10, 2016
1 parent 91582dc commit a0902c3
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions client/rpcproxy/rpcproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a0902c3

Please sign in to comment.