summaryrefslogtreecommitdiff
path: root/modules/caddyhttp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r--modules/caddyhttp/reverseproxy/selectionpolicies.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/modules/caddyhttp/reverseproxy/selectionpolicies.go b/modules/caddyhttp/reverseproxy/selectionpolicies.go
index a2985f1..35fb143 100644
--- a/modules/caddyhttp/reverseproxy/selectionpolicies.go
+++ b/modules/caddyhttp/reverseproxy/selectionpolicies.go
@@ -187,7 +187,7 @@ func (LeastConnSelection) Select(pool UpstreamPool, _ *http.Request, _ http.Resp
// sample: https://en.wikipedia.org/wiki/Reservoir_sampling
if numReqs == leastReqs {
count++
- if (weakrand.Int() % count) == 0 { //nolint:gosec
+ if count > 1 || (weakrand.Int()%count) == 0 { //nolint:gosec
bestHost = host
}
}
@@ -707,6 +707,9 @@ func leastRequests(upstreams []*Upstream) *Upstream {
if len(best) == 0 {
return nil
}
+ if len(best) == 1 {
+ return best[0]
+ }
return best[weakrand.Intn(len(best))] //nolint:gosec
}