Skip to content

Commit

Permalink
fix overflow in peer selection
Browse files Browse the repository at this point in the history
  • Loading branch information
adg committed Aug 12, 2013
1 parent b3105e2 commit 3f89d3e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ func (p *HTTPPool) PickPeer(key string) (ProtoGetter, bool) {
if len(p.peers) == 0 {
return nil, false
}
if peer := p.peers[int(h)%len(p.peers)]; peer != p.self {
n := int(h)
if n < 0 {
n *= -1
}
if peer := p.peers[n%len(p.peers)]; peer != p.self {
// TODO: pre-build a slice of *httpGetter when Set()
// is called to avoid these two allocations.
return &httpGetter{p.Transport, peer + p.basePath}, true
Expand Down

0 comments on commit 3f89d3e

Please sign in to comment.