caddyserver/caddy · error

weight of an upstream cannot be negative

Error message

weight of an upstream cannot be negative

What it means

Error "weight of an upstream cannot be negative" thrown in caddyserver/caddy.

Source

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

	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
	var weights []int

	for _, w := range r.Weights {
		if w > 0 {

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Set all upstream weights to zero or a positive value.

When it happens

Trigger: Thrown at modules/caddyhttp/reverseproxy/selectionpolicies.go:137 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/65b2b6044af37a84. Report an issue: GitHub.