@marcel91200 / caddy Mirror · read-only / commits / aeea18be
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 11, 01:00 UTC

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.

D'Ali Ben Macha committed Nov 3, 2026 at 08:01 UTC aeea18be86b7a91cbc87be69a817a41ecff951de
2 files changed +21
modules/caddyhttp/reverseproxy/selectionpolicies.go
+3
@@ -146,6 +146,9 @@ func (r *WeightedRoundRobinSelection) Select(pool UpstreamPool, _ *http.Request,
146 return nil
147 }
148 if len(r.Weights) < 2 {
149 + if !pool[0].Available() {
150 + return nil
151 + }
152 return pool[0]
153 }
154 var index, totalWeight int
modules/caddyhttp/reverseproxy/selectionpolicies_test.go
+18
@@ -148,6 +148,24 @@ func TestWeightedRoundRobinPolicyFewerWeightsThanUpstreams(t *testing.T) {
148 }
149 }
150
151 +func TestWeightedRoundRobinPolicySingleWeight(t *testing.T) {
152 + pool := testPool()
153 + wrrPolicy := WeightedRoundRobinSelection{
154 + Weights: []int{1},
155 + totalWeight: 1,
156 + }
157 + req, _ := http.NewRequest("GET", "/", nil)
158 +
159 + if h := wrrPolicy.Select(pool, req, nil); h != pool[0] {
160 + t.Errorf("got %v, want the only weighted host %v", h, pool[0])
161 + }
162 +
163 + pool[0].setHealthy(false)
164 + if h := wrrPolicy.Select(pool, req, nil); h != nil {
165 + t.Errorf("got %v, want nil when the only weighted host is unavailable", h)
166 + }
167 +}
168 +
169 func TestWeightedRoundRobinSelection_Validate(t *testing.T) {
170 tests := []struct {
171 name string