summaryrefslogtreecommitdiffhomepage
path: root/caddyhttp/proxy/policy.go
diff options
context:
space:
mode:
Diffstat (limited to 'caddyhttp/proxy/policy.go')
-rw-r--r--caddyhttp/proxy/policy.go13
1 files changed, 4 insertions, 9 deletions
diff --git a/caddyhttp/proxy/policy.go b/caddyhttp/proxy/policy.go
index 1737c6c58..337ad1e83 100644
--- a/caddyhttp/proxy/policy.go
+++ b/caddyhttp/proxy/policy.go
@@ -121,18 +121,13 @@ func (r *IPHash) Select(pool HostPool, request *http.Request) *UpstreamHost {
if err != nil {
clientIP = request.RemoteAddr
}
- hash := hash(clientIP)
- for {
- if poolLen == 0 {
- break
- }
- index := hash % poolLen
- host := pool[index]
+ index := hash(clientIP) % poolLen
+ for i := uint32(0); i < poolLen; i++ {
+ index += i
+ host := pool[index%poolLen]
if host.Available() {
return host
}
- pool = append(pool[:index], pool[index+1:]...)
- poolLen--
}
return nil
}