diff options
author | Dimitri Masson <30894448+d-masson@users.noreply.github.com> | 2020-11-16 20:47:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-16 12:47:15 -0700 |
commit | 99b8f44486b766f220a33906d84ac05af942f260 (patch) | |
tree | 42fc7d997937e940e444e94dd8ac0e4cf1384757 /modules/caddyhttp/reverseproxy/selectionpolicies.go | |
parent | 670b723e3802ac37942dad07dc194539bccce9ff (diff) |
reverse_proxy: Fix random_choose selection policy (#3811)
Diffstat (limited to 'modules/caddyhttp/reverseproxy/selectionpolicies.go')
-rw-r--r-- | modules/caddyhttp/reverseproxy/selectionpolicies.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/modules/caddyhttp/reverseproxy/selectionpolicies.go b/modules/caddyhttp/reverseproxy/selectionpolicies.go index 343140f..2aef63d 100644 --- a/modules/caddyhttp/reverseproxy/selectionpolicies.go +++ b/modules/caddyhttp/reverseproxy/selectionpolicies.go @@ -397,13 +397,18 @@ func leastRequests(upstreams []*Upstream) *Upstream { return nil } var best []*Upstream - var bestReqs int + var bestReqs int = -1 for _, upstream := range upstreams { + if upstream == nil { + continue + } reqs := upstream.NumRequests() if reqs == 0 { return upstream } - if reqs <= bestReqs { + // If bestReqs was just initialized to -1 + // we need to append upstream also + if reqs <= bestReqs || bestReqs == -1 { bestReqs = reqs best = append(best, upstream) } |