caddyserver/caddy · error

weighted_round_robin requires at least one upstream with a…

Error message

weighted_round_robin requires at least one upstream with a positive weight

What it means

Validation guard in WeightedRoundRobinSelection.Validate: after Provision sums the upstream weights, totalWeight is <= 0, meaning every upstream has weight 0 or none was given a positive weight. The faulty input is the lb_policy weighted_round_robin upstream weight list; at least one weight must be > 0.

Solutions

  1. Give at least one upstream a positive weight in the weighted_round_robin policy.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at modules/caddyhttp/reverseproxy/selectionpolicies.go:133 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15). Data as JSON: /api/errors/26fb973c0a87753f. Report an issue: GitHub.

Appendix: source

Thrown at modules/caddyhttp/reverseproxy/selectionpolicies.go:133

			return d.Errf("invalid weight value '%s': weight should be non-negative", weight)
		}
		r.Weights = append(r.Weights, weightInt)
	}
	return nil
}

// Provision sets up r.
func (r *WeightedRoundRobinSelection) Provision(ctx caddy.Context) error {
	for _, weight := range r.Weights {
		r.totalWeight += weight
	}
	return nil
}

// Validate ensures that r's configuration is valid
func (r *WeightedRoundRobinSelection) Validate() error {
	if r.totalWeight <= 0 {
		return fmt.Errorf("weighted_round_robin requires at least one upstream with a positive weight")
	}
	for _, weight := range r.Weights {
		if weight < 0 {
			return fmt.Errorf("weight of an upstream cannot be negative")
		}
	}
	return nil
}

// Select returns an available host, if any.
func (r *WeightedRoundRobinSelection) Select(pool UpstreamPool, _ *http.Request, _ http.ResponseWriter) *Upstream {
	if len(pool) == 0 {
		return nil
	}
	if len(r.Weights) < 2 {
		return pool[0]
	}
	var index, totalWeight int

View on GitHub (pinned to 50e54ee279)