Repository navigation
fix(cli): name the load-balancing values the parser actually accepts - #1441
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 22, 2026 11:12
FlorentinDUBOIS
force-pushed
the
fix/cli-load-balancing-help
branch
from
September 22, 2026 14:21
df6aa7c to
828ecb0
Compare
… stated
`H2FloodConfig::new` clamps every threshold to `>= 1` and nothing in
production called it: `get_h2_flood_config` in `lib/src/http.rs` and
`lib/src/https.rs` built the struct with a raw literal, so only
`Default::default()`'s compile-time constants -- which never needed
validation -- went through the clamp, and every value an operator can
actually set bypassed it.
A `0` there does not disable a check. `check_flood` compares
`count > threshold`, so it makes the first event that counter sees a
violation, with no error at load time and no log explaining it. How far
that reaches depends on the knob. `h2_max_header_list_size` and
`h2_max_header_fields` are also the HPACK decode budget
`pkawa::decode_headers_with_budget` enforces, so `0` makes the first
header field of every block exceed it (name + value + the 32-octet
RFC 9113 6.5.2 overhead) and every request on the listener is refused
with `ENHANCE_YOUR_CALM`: per stream for a header block that fits one
HEADERS frame, and as a connection `GOAWAY` for one that spans
CONTINUATION frames, where `record_continuation_frame` lifts
`accumulated_header_size` above the zero threshold and
`check_flood_or_return!` fires ahead of the explicit size test.
`h2_max_header_table_size` is not in that class -- `0` there only zeroes
the HPACK encoder's dynamic table. The per-window and lifetime frame
counters are inert until a client sends the frame they count:
`h2_max_rst_stream_per_window = 0` costs nothing on a connection that
never sends RST_STREAM, since `0 > 0` is false, and tears the connection
down on the first one that does.
A debug build fired `H2FloodDetector::new`'s pre-condition assertion
instead -- an assertion whose comment blamed a "raw struct literal in a
future caller" that was already there. It now covers all thirteen
thresholds rather than five, because `impl Default` is itself an
in-module struct literal and a future `DEFAULT_MAX_HEADER_LIST_SIZE = 0`
would otherwise pass unnoticed.
Every door that STATES a listener configuration now refuses the value.
`ListenerBuilder::to_http`/`to_tls` return
`ConfigError::H2ThresholdBelowMinimum`, naming the listener, the key, the
value and the minimum; `validate_h2_flood_knobs_http`/`_https` already
refused it on `UpdateHttp(s)Listener`; and a raw protobuf
`Add{Http,Https}Listener` straight to the command socket -- which reached
neither, so `ConfigState::add_http_listener` cloned it in unvalidated and
every worker rewrote the `0` to `1` -- is now gated by
`bin/src/command/requests.rs::validate_h2_knob_floors`, before the
address is reserved. All five validators expand one shared list,
`for_each_h2_knob_floor!` in `command/src/lib.rs`, instead of keeping
five copies of the same fifteen knobs: adding a knob to one door and
forgetting another is how this bug would come back one level up, and it
is no longer expressible.
Replay is deliberately NOT one of those doors. `LoadState` skips an entry
its pre-dispatch validation rejects, and a skipped listener never binds,
so applying the rejection there would take every frontend behind an
already-serving listener offline -- an HTTPS listener takes its whole TLS
surface with it -- to prevent one clamped threshold. The other two gates
reject configurations that cannot function; an out-of-range threshold
builds, clamps, and serves. Be exact about the clamp's direction: `flag`
is `count > threshold`, so `0` trips on the FIRST counted event and the
clamped `1` on the second. The clamp loosens every knob it touches, by
exactly one event. That is still the right trade on replay, because `0`
is not "no limit" and not a protection level anyone tuned -- what it
cannot do is switch detection off. `validate_request` therefore takes a
`RequestOrigin`: `Authored` enforces the floors, `Replayed` keeps the
listener and warns with the key to fix, counting
`config.load_h2_knob_clamped`. `bin/src/cli.rs`'s
`--h2-stream-shrink-ratio` help said "must be >= 1" against a floor of 2,
on both the HTTP and the HTTPS update subcommand; with the floor now
single-sourced, the help agrees with it.
`H2FloodConfig`'s thirteen fields become private with `pub` accessors,
matching `hpack_state`, `h2_flow_control` and `h2_stream_table`.
`H2FloodConfig::from_optional` -- the same shape as the adjacent
`H2ConnectionConfig::from_optional` that `get_h2_connection_config`
already uses -- resolves each `None` to its default and delegates to
`new`, and both listeners call it. The clamp is the backstop for the one
path that deliberately does not reject. A new per-field test in each
listener pins the thirteen positional arguments `get_h2_flood_config`
hands `from_optional`, where a transposition within the ten `u32`s or the
three `u64`s would otherwise compile silently.
Closes #1418
Signed-off-by: Florentin Dubois <[email protected]>
The flag's help advertised 'roundrobin', 'random' and 'leastconnections', while the value is consumed by `FromStr for LoadBalancingAlgorithms` (command/src/request.rs:301), which matches only round_robin, random, power_of_two, least_loaded, hrw and maglev, case-insensitively via `s.to_lowercase()`. Two of the three advertised spellings matched no arm and four accepted values went undocumented. Because the field is typed LoadBalancingAlgorithms, clap resolves a FromStr-backed value parser and rejects a bad value during argument parsing, before any I/O: `sozu cluster add --id demo --load-balancing-policy roundrobin` exits 2 with `invalid value 'roundrobin'`. Since --load-balancing-policy is a required argument, a user following the help could not create a cluster at all — an unusable flag, not merely a stale comment. A FromStr-backed parser also carries no value enumeration, so clap renders no `[possible values: ...]` line: the help string was the only list a user ever saw. `roundrobin` was orphaned by 7555d38 (2022-12-18 UTC), which renamed the accepted spelling to round_robin in the parser without sweeping the CLI or the docs; `leastconnections` matched no arm even before that. doc/configure_cli.md repeated the rejected value in two copy-pasteable commands, and doc/architecture.md named four of the six algorithms; both are corrected in the same changeset. Two guards derive the expected list from the protobuf enum itself — LoadBalancingAlgorithms::try_from scanned across every discriminant below a documented bound, then as_str_name().to_lowercase(), which is exactly the spelling FromStr accepts — rather than restating it. The scan deliberately does not stop at the first gap: `reserved 6;` beside `WEIGHTED = 7;` is the canonical way to retire a protobuf enum value, and a scan that broke there would skip the new variant and pass green while the help omitted it. Adding an algorithm to command/src/command.proto therefore fails the suite until the help names it, for any discriminant below that bound; a discriminant at or beyond it is the single residual case these guards do not cover for a proto-declared variant. What they compare is the proto enum against the help, so a hand-written FromStr arm with no proto counterpart — an alias such as `"rr" => RoundRobin` — is outside what they can see: the CLI would accept it while the help never named it. Adding an alias means naming it in the help by hand. Closes #1429 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
fix/cli-load-balancing-help
branch
from
September 22, 2026 16:14
828ecb0 to
6fff9d0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The flag's help advertised 'roundrobin', 'random' and 'leastconnections',
while the value is consumed by
FromStr for LoadBalancingAlgorithms(command/src/request.rs:301), which matches only round_robin, random,
power_of_two, least_loaded, hrw and maglev, case-insensitively via
s.to_lowercase(). Two of the three advertised spellings matched no armand four accepted values went undocumented.
Because the field is typed LoadBalancingAlgorithms, clap resolves a
FromStr-backed value parser and rejects a bad value during argument
parsing, before any I/O:
sozu cluster add --id demo --load-balancing-policy roundrobinexits 2 withinvalid value 'roundrobin'. Since --load-balancing-policy is a required argument, auser following the help could not create a cluster at all — an unusable
flag, not merely a stale comment. A FromStr-backed parser also carries no
value enumeration, so clap renders no
[possible values: ...]line: thehelp string was the only list a user ever saw.
roundrobinwas orphaned by 7555d38 (2022-12-18 UTC), which renamed theaccepted spelling to round_robin in the parser without sweeping the CLI
or the docs;
leastconnectionsmatched no arm even before that.doc/configure_cli.md repeated the rejected value in two copy-pasteable
commands, and doc/architecture.md named four of the six algorithms; both
are corrected in the same changeset.
Two guards derive the expected list from the protobuf enum itself —
LoadBalancingAlgorithms::try_from scanned across every discriminant below
a documented bound, then as_str_name().to_lowercase(), which is exactly
the spelling FromStr accepts — rather than restating it. The scan
deliberately does not stop at the first gap:
reserved 6;besideWEIGHTED = 7;is the canonical way to retire a protobuf enum value, anda scan that broke there would skip the new variant and pass green while
the help omitted it. Adding an algorithm to command/src/command.proto
therefore fails the suite until the help names it, for any discriminant
below that bound; a discriminant at or beyond it is the single residual
case these guards do not cover for a proto-declared variant. What they
compare is the proto enum against the help, so a hand-written FromStr arm
with no proto counterpart — an alias such as
"rr" => RoundRobin— isoutside what they can see: the CLI would accept it while the help never
named it. Adding an alias means naming it in the help by hand.
Closes #1429
Signed-off-by: Florentin Dubois [email protected]