Skip to content

reverseproxy: validate on weighted_round_robin loadbalancing policy - #7807

Merged
steadytao merged 6 commits into
caddyserver:masterfrom
vijayvenkatj:master
Jun 7, 2026
Merged

steadytao merged 6 commits into
caddyserver:masterfrom
vijayvenkatj:master

Conversation

@vijayvenkatj

Copy link
Copy Markdown
Contributor

Fixes issue #7806

Validate that weighted_round_robin has a non-zero total weight.
This prevents configurations such as:
weighted_round_robin 0 0
from being accepted and causing a divide-by-zero panic during request handling.

Assistance Disclosure

The initial test template was generated using Gemini 3.1 and then manually edited.

Validate that weighted_round_robin has a non-zero total weight.
This prevents configurations such as:
    weighted_round_robin 0 0
from being accepted and causing a divide-by-zero panic during request handling.

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly reasonable to me. Just some small issues.

steadytao

This comment was marked as outdated.

@vijayvenkatj

Copy link
Copy Markdown
Contributor Author

One remaining JSON-config gap is that Caddyfile parsing rejects negative weights but direct JSON config can still set them because Validate() only checks totalWeight == 0.

Since this is now the module-level validation path, it should also reject any weight < 0 while still allowing 0 when at least one other weight is positive.

I've now changed validate to check for negative weights.

steadytao

This comment was marked as outdated.

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. This keeps 0 weights valid for skipped upstreams, rejects zero-total and negative-weight configurations at the module validation layer and covers the JSON-config path as well.

@steadytao steadytao added the bug 🐞 Something isn't working label Jun 7, 2026
@steadytao
steadytao merged commit 55b3397 into caddyserver:master Jun 7, 2026
26 checks passed
@steadytao

Copy link
Copy Markdown
Member

Thanks for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐞 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants