Skip to content

Commit

Permalink
polcies: dont mark a removed host
Browse files Browse the repository at this point in the history
Dont mark a host which has been removed from the policy/pools, this
fixes a race where the pool can remove the policies host, then a query
which is using the host will try to mark the host, which does not exist
in the underlying hostpool, causing a log.Fatalf/panic.

Fix this by checking the policy still has the host we want to mark, and
do so whilst holding the mutex read lock so that the hostpool will not
change.
  • Loading branch information
Zariel committed Mar 24, 2016
1 parent 2659724 commit ee01750
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,22 +485,35 @@ func (r *hostPoolHostPolicy) Pick(qry *Query) NextHost {
return nil
}

return selectedHostPoolHost{host, hostR}
return selectedHostPoolHost{
policy: r,
info: host,
hostR: hostR,
}
}
}

// selectedHostPoolHost is a host returned by the hostPoolHostPolicy and
// implements the SelectedHost interface
type selectedHostPoolHost struct {
info *HostInfo
hostR hostpool.HostPoolResponse
policy *hostPoolHostPolicy
info *HostInfo
hostR hostpool.HostPoolResponse
}

func (host selectedHostPoolHost) Info() *HostInfo {
return host.info
}

func (host selectedHostPoolHost) Mark(err error) {
host.policy.mu.RLock()
defer host.policy.mu.RUnlock()

if _, ok := host.policy.hostMap[host.info.Peer()]; !ok {
// host was removed between pick and mark
return
}

host.hostR.Mark(err)
}

Expand Down

0 comments on commit ee01750

Please sign in to comment.