reverseproxy: skip unavailable upstream with a single weighted_round_robin weight (#8320)

With fewer than two weights, WeightedRoundRobinSelection returned the
first upstream without checking that it is available.
This commit is contained in:
D'Ali Ben Macha authored and GitHub committed 2026-11-03 07:01:28 +00:00
1 parent cce035d7ad
commit aeea18be86
2 files changed
+21

No files matched your search

@@ -146,6 +146,9 @@ func (r *WeightedRoundRobinSelection) Select(pool UpstreamPool, _ *http.Request,
return nil
}
if len(r.Weights) < 2 {
if !pool[0].Available() {
return nil
}
return pool[0]
}
var index, totalWeight int
@@ -148,6 +148,24 @@ func TestWeightedRoundRobinPolicyFewerWeightsThanUpstreams(t *testing.T) {
}
}
func TestWeightedRoundRobinPolicySingleWeight(t *testing.T) {
pool := testPool()
wrrPolicy := WeightedRoundRobinSelection{
Weights: []int{1},
totalWeight: 1,
}
req, _ := http.NewRequest("GET", "/", nil)
if h := wrrPolicy.Select(pool, req, nil); h != pool[0] {
t.Errorf("got %v, want the only weighted host %v", h, pool[0])
}
pool[0].setHealthy(false)
if h := wrrPolicy.Select(pool, req, nil); h != nil {
t.Errorf("got %v, want nil when the only weighted host is unavailable", h)
}
}
func TestWeightedRoundRobinSelection_Validate(t *testing.T) {
tests := []struct {
name string