Skip to content

fix(mux-h2): raise H2 flood-protection defaults and scale RST caps with answered streams - #1756

Merged
FlorentinDUBOIS merged 8 commits into
mainfrom
fix/h2-flood-thresholds
Oct 2, 2026
Merged

FlorentinDUBOIS merged 8 commits into
mainfrom
fix/h2-flood-thresholds

Conversation

@FlorentinDUBOIS

@FlorentinDUBOIS FlorentinDUBOIS commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Raise H2 flood-protection defaults that tripped on legitimate traffic; scale RST caps with the streams a backend answered; stop counting Sōzu-initiated resets.

Fixes #1749

Changes

  • Stream-0 WINDOW_UPDATE: an update answering DATA Sōzu sent is credited (two per DATA frame, after Envoy's max_inbound_window_update_frames_per_data_frame_sent); stored credit is capped by the DATA sent recently and decays once DATA stops. h2_max_window_update_stream0_per_window bounds only unsolicited updates (RFC 9113 §6.9 leaves the cadence to the peer).
  • RST caps relative to backend-routed streams: the three h2_max_rst_stream_*_lifetime knobs become floors. Backend-routed streams are those a backend answered, those Sōzu answered 502/503/504 after selecting a backend, and those it answered 503 because every backend of the cluster was failing; refused streams and streams answered without a backend for another reason (no route, a cluster with no backend, a session or buffer limit) do not count. Pre-response resets received and peer-provoked resets emitted share one count and trip once they exceed the streams a backend answered, i.e. more than half of the backend-routed streams (Envoy's 50 % line). h2_max_rst_stream_lifetime compares only the resets received after a response started or on a closed stream with the answered streams; a stream reset after its response counts as answered before the check, so cancelling answered streams never trips it. No absolute per-connection reset ceiling is added.
  • Sōzu-initiated resets (idle-reaper CANCEL, REFUSED_STREAM, STREAM_CLOSED, converter errors on a backend failure) no longer feed the CVE-2025-8671 cap. Each peer-provoked reset also counts as a glitch.
  • Refused streams: counted as glitches once the client has acknowledged our SETTINGS (buffer-pool refusals excepted); their ids are no longer kept in the per-connection reset set.
  • Backend connections: a RST_STREAM a backend sends before its response is not counted as Rapid Reset.
  • Pending RST queue: bounded on what is pending (at least 4000, or four per advertised h2_max_concurrent_streams); GOAWAY only when an RST could not be queued.
  • Defaults ×20 for every count threshold: per-window RST/PING/empty-DATA/stream-0 WINDOW_UPDATE 2000, SETTINGS 1000, glitch 2000, RST floors 200 000 / 1000 / 10 000, PING/SETTINGS lifetime 200 000, pending RST floor 4000, back-pressure 1000 refusals per 60 s.
  • Memory bounds unchanged: h2_max_header_list_size, h2_max_header_fields (128), h2_max_continuation_frames, h2_max_header_table_size, the PRIORITY map size and buffer sizes.
  • doc/configure.md, doc/h2_mux_internals.md, LIFECYCLE.md, bin/config.toml, proto/config/CLI help and CHANGELOG.md updated.

Reference defaults compared: nghttp2 (reset burst 1000 / 33 s⁻¹, glitch 10 000 / 330 s⁻¹, outbound queue 1000), Go x/net/http2 (queued control frames 10 000), hyper h2 (local error resets 1024), Envoy (premature reset ≥ 50 % of ≥ 500 streams, WINDOW_UPDATE per DATA frame sent, outbound control frames 1000).

Tests

New, each seen failing without its fix and passing with it:

  • e2e test_h2_pre_response_cancels_keep_the_connection, test_h2_per_frame_connection_window_updates_do_not_trip
  • local_resets_are_not_charged_to_the_peer, backend_resets_before_the_response_are_not_rapid_reset
  • e2e test_h2_cancels_during_a_backend_outage_keep_the_connection; test_flood_detector_pre_response_cap_trips_only_above_half, test_flood_detector_window_update_credit_covers_data_in_flight
  • refused_streams_keep_rst_sent_bounded_and_trip_the_glitch_budget, peer_provoked_resets_count_as_glitches, unanswered_streams_do_not_dilute_the_reset_caps, test_flood_detector_pre_response_caps_share_one_count
  • resets_after_the_response_never_trip_the_lifetime_cap, pre_response_resets_do_not_count_toward_the_lifetime_cap, a_5xx_answered_without_a_backend_is_not_routed, a_5xx_answered_during_a_backend_outage_is_routed; guard resets_of_streams_already_gone_trip_the_lifetime_cap
  • detector and control-queue unit tests (ratio caps, WINDOW_UPDATE credit and its cap, pending bound)

Existing flood tests keep their assertions; only their frame counts rise above the new thresholds.

Validation

  • cargo +nightly fmt --all -- --check
  • cargo +1.93.1 clippy --all-features --all-targets --locked -- -D warnings
  • RUSTDOCFLAGS="-D warnings" cargo doc --all-features --no-deps
  • cargo test --all-features --locked -p sozu-command-lib -p sozu-lib -p sozu
  • targeted cargo test -p sozu-e2e --locked --features opentelemetry,splice,simd (flood, rapid reset, GOAWAY, h2spec)
  • cargo +nightly fuzz build
  • check_doc_citations.py in its four modes

@FlorentinDUBOIS FlorentinDUBOIS changed the title fix(mux-h2): raise H2 flood-protection defaults and make RST caps decay fix(mux-h2): raise H2 flood-protection defaults and scale RST caps with answered streams Oct 1, 2026
Raise H2 flood-protection defaults that tripped on legitimate traffic;
make RST caps decay; stop counting Sōzu-initiated resets.

- Stream-0 WINDOW_UPDATEs answering DATA sent are credited (two per DATA
  frame); h2_max_window_update_stream0_per_window bounds only unsolicited
  ones.
- The received, pre-response and peer-provoked emitted RST caps trip only
  once their count also exceeds the streams opened (received) or half of
  them (the other two); the configured values become floors.
- Resets Sōzu decides on its own (idle CANCEL, REFUSED_STREAM from its
  concurrency limit, back-pressure or buffer pool, STREAM_CLOSED,
  converter errors) no longer count toward the CVE-2025-8671 cap.
- On a backend connection, backend resets before the response are not
  counted as Rapid Reset.
- The pending RST_STREAM queue bound limits what is pending, not the
  connection's lifetime; GOAWAY only when an RST could not be queued.
- Count defaults x20: per-window RST/PING/empty-DATA/WINDOW_UPDATE 2000,
  SETTINGS 1000, glitch 2000, RST lifetime floors 200000/1000/10000,
  PING/SETTINGS lifetime 200000, pending RST floor 4000, back-pressure
  1000 refusals per 60 s. Memory bounds are unchanged.
- A stream beyond the advertised max_concurrent_streams counts as a
  glitch (RFC 9113 §5.1.2).

Fixes #1749

Signed-off-by: Florentin Dubois <[email protected]>
…T ratio

- Do not record never-registered stream ids (refused streams, DATA on a
  closed stream) in the RST dedupe set; only stream-table eviction
  removes an id from it.
- Count every refused stream as a glitch once the peer has acknowledged
  our SETTINGS (buffer-pool refusals excepted).
- Compare pre-response resets received and peer-provoked resets emitted
  as one count against half of the answered streams.
- Count each peer-provoked reset as a glitch.
- Count toward the RST caps' denominator only the frontend streams a
  backend answered.
- Cap the stored stream-0 WINDOW_UPDATE credit.

Refs #1749

Signed-off-by: Florentin Dubois <[email protected]>
…streams

- Trip the pre-response caps once pre-response resets exceed the
  answered streams, i.e. more than half of all backend-routed streams
  were reset before their response.
- Count a stream answered 502/503/504 by Sōzu, or with a selected
  backend, as backend-routed.
- Size the stream-0 WINDOW_UPDATE credit cap on the DATA frames sent
  recently, decaying with the flood window.

Refs #1749

Signed-off-by: Florentin Dubois <[email protected]>
…ncels

A frontend stream reset after its response started now counts as answered
before the RST caps are checked, and the received-RST lifetime cap compares
only the resets outside the pre-response count (after a response, or on a
stream already gone) with the answered streams. A client that cancels every
stream after its response, or mixes pre- and post-response cancels, no
longer trips it past its floor.

A 502/503/504 stream counts toward the caps' denominator only when a backend
was selected for it, or when its cluster has backends and every one of them
is failing (the outage case, flagged on the request context). A 503 for a
cluster with no backend, a session or buffer limit hit before selection, or
a routing error no longer dilutes the ratio.

Docs, CLI help and the configuration example now state the exact ratios.

Signed-off-by: Florentin Dubois <[email protected]>
Rebasing onto main moved the h2.rs lines doc/h2_mux_internals.md pins, and
placed the flood-threshold CHANGELOG entry inside an existing one. Repoint
the pinned blocks at the lines they quote and put the entry back at the top
of its section.

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS force-pushed the fix/h2-flood-thresholds branch from b33416c to 615b8a2 Compare October 1, 2026 22:24
Resolve the overlap with #1753 in the closed-stream arms of
ConnectionH2::handle_frame. Main's HEADERS arm for a stream this endpoint
reset (discard the payload, continue) is kept as is. On the DATA arm, the
RST_STREAM(STREAM_CLOSED) sent for a stream not reset locally takes this
branch's third enqueue_rst argument, RstOrigin::Local: that DATA is
already counted as a glitch just above, which bounds it, and charging it
to the provoked-RST cap too would count it twice. The old comment's other
reason, that such DATA is usually the tail of a stream sozu reset, no
longer applies: main now ignores that case before this call.

doc/configure.md keeps this branch's flood-threshold rows and main's
h2_initial_connection_window default; doc/h2_mux_internals.md citations
are re-anchored to the merged code.

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 933eba0 into main Oct 2, 2026
23 checks passed
FlorentinDUBOIS added a commit that referenced this pull request Oct 2, 2026
Resolve the closed-stream arms of ConnectionH2::handle_frame against #1756.
This branch ignores the DATA and HEADERS a peer sent on a stream sozu reset
in one earlier read-side branch, so main's was_reset_locally arms at this
point (DATA if/else and HEADERS) are dropped in favour of this branch's
structure. The RST_STREAM(STREAM_CLOSED) still sent for DATA on any other
closed stream takes #1756's third enqueue_rst argument, RstOrigin::Local,
as #1756 chose for the same site: that DATA is already counted as a glitch
just above, which bounds it, and charging it to the provoked-RST cap too
would count it twice. refuse_stream_and_discard and its four callers merged
cleanly with #1756's origin parameter (RstOrigin::Local for every refusal).

lib/src/protocol/mux/LIFECYCLE.md keeps main's rewritten RST-bound bullets
and this branch's paragraph on recently reset streams; doc/h2_mux_internals.md
citations are re-anchored to the merged code.

Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS added a commit that referenced this pull request Oct 2, 2026
header_blocks_on_a_reset_backend_stream_beyond_two_count_glitches and
empty_data_frames_on_a_reset_backend_stream_count_toward_the_flood_limit
flood a backend connection until GOAWAY(ENHANCE_YOUR_CALM), with a bounded
number of frames sized for the flood defaults of the time. #1756 raised
DEFAULT_MAX_GLITCH_COUNT and DEFAULT_MAX_EMPTY_DATA_PER_WINDOW from 100 to
2000, so after main was merged in neither flood reached its limit and both
tests failed on their final GOAWAY assertion, while the counting they check
still worked.

Each test now sets the one limit it exercises to 100 through
H2FloodConfig::from_optional, as unanswered_streams_do_not_dilute_the_reset_caps
does, so it checks the counting logic whatever the defaults are. The
empty-DATA test keeps the default glitch limit so its GOAWAY can only come
from the empty-DATA count. No assertion changes.

Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS added a commit that referenced this pull request Oct 2, 2026
a_refused_control_frame_drain_leaves_writable_to_the_kernel, added on this
branch, queues its RST_STREAM with ConnectionH2::enqueue_rst(id, error).
#1756 gave enqueue_rst a third RstOrigin argument and updated the existing
drain tests, so once main was merged in this new test no longer compiled:
the two changes touched different lines and merged without a textual
conflict.

Pass RstOrigin::Local, as the sibling drain test just above it does: the
reset is one sozu queues itself, not one a peer provoked, and the test only
needs one queued RST_STREAM to drain.

Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS added a commit that referenced this pull request Oct 3, 2026
…1809)

Audit of the docs, `bin/config.toml` and `os-build/config.toml` against everything merged on `main` from 2026-10-01 to 2026-10-03 (43 commits, #1724 through #1808). Most of the new keys were already documented by their own PRs (`max_connection_attempts`, `h2_stream_refusal_percent`, health check `mode`/`accepted_statuses`, the raised flood defaults, the 16 MiB connection window). This PR fixes what was still stale.

| Area | Where | Was | Now |
|---|---|---|---|
| #1806 | `bin/config.toml`, `os-build/config.toml` answer comments | 503 only for "no backend available"; "504 means the backend timed out" | 503 also when every attempt failed; 504 = connected backend silent or frontend timeout while waiting; connect timeout fails over |
| #1806 | `bin/config.toml` `max_connection_attempts` | connect timeout always fails over | a TCP session whose connect times out is closed |
| #1806 | `doc/debugging_strategies.md` | 503 after a circuit breaker of 3 failed connections; ERROR log lines, one that no longer exists | `max_connection_attempts` (default 5), `backend.connect.retries_exhausted`, real TCP log levels and text |
| #1806 | `doc/configure.md` `front_timeout` / `connect_timeout` rows | "inactivity for a request to connect" | time to establish a backend connection; HTTP fails over, TCP closes; H1 failover bound by `front_timeout` |
| #1806 | `doc/configure.md` `client_timeout_during_response`, `backend_timeout`, `http.503.errors` | "connection-level slowness", "circuit breaker" | failover case included; established connection only; attempt budget |
| #1806 | `LIFECYCLE.md` backend timer | 504 for any linked stream | established connection only |
| #1806 | `cli.rs` help, `doc/configure_cli.md` | "answered 503" | "or a TCP session is closed" |
| #1756 | `doc/configure.md` flood metrics | RST lifetime rows described as absolute ceilings; no `window_update_stream0_window` row | floor-and-ratio semantics; row added |
| #1756/#1798 | `doc/architecture.md`, `doc/h2_mux_internals.md` | 6 / 13 `H2FloodConfig` thresholds | 14, with `h2_stream_refusal_percent` |
| #1756 | `doc/configure_admin_ops.md` | "halve" example 50/25 (old defaults); H2 knobs HTTPS only | 1000/500; HTTP and HTTPS; `h2.flood.stream_refused` |
| #1752 | `doc/configure.md` glitch tuning | "1 MiB window ... about 64" frames | 64 KiB stream window, about four |
| #1805 | `doc/health_checks.md` | `remove` resets backends to healthy; DOWN logs an error; `load_balancing.rs::BackendList::healthy` | backends keep their last state (see note); warning; `BackendList::select_tiers` in `backends.rs` |
| #1805 | `doc/metrics.md` | health-check counters "per cluster" | unlabelled |
| #1805 | `doc/configure_cli.md` | no health-check section | short section, `--mode`, `--probe-timeout` vs global `--timeout` |
| #1746 | `cli.rs` `--load-balancing-policy`, `bin/config.toml`, proto comment | HRW/MAGLEV key = UDP flow key | UDP affinity key (source IP, or IP and port) |
| UDP | `doc/configure.md` | hot upgrade drains flows bounded by idle timeout; `udp.flows.evicted` reasons | soft-stop closes flows at once; listener removal/soft-stop/abort added |
| #1770 | `doc/udp_simulation.md` | no per-source limits | in reconfig storms and the invariant list |
| #1743 | `doc/lifetime_of_a_session.md` | keep-alive backend always reused | unless its backend was removed |
| older | `command.proto` update messages | `h2_stream_shrink_ratio >= 1` | `>= 2`, as validated in `state.rs` |
| #1806 | e2e shuffle-sharding doc comment | "three connection attempts" | `max_connection_attempts` (5 by default) |

Reported here, not changed in this PR:
- `sozu cluster health-check remove` does not reset backends a probe marked DOWN (`remove_health_check_state` skips the reset that `set_health_check_config(None)` does), so they stay out of rotation until the cluster is added again. The doc now describes this. It looks like a code bug.
- `sozu top`'s H2 pane reads `h2.flood.violation.{rapid_reset,made_you_reset,ping,settings,priority,continuation}`, which the detector never emits (it emits `rst_stream_pre_response_lifetime`, `ping_window`, ...). Only `glitch_window` matches, and `h2.flood.stream_refused` is not shown.
- `h2_flood_detector.rs` comments still refer to a 1 MiB connection window, and the `h2_stream_idle_timeout_seconds` proto comment says "Default: 30" where the value inherits `back_timeout`.
- `connections.rejected_per_cluster_ip` is documented as also counting TCP rejections; only the HTTP 429 path increments it.

Validation:
- `sozu config check` passes on `bin/config.toml`, on a copy with every commented key under review uncommented (global and cluster `max_connection_attempts`, the H2 block, the health check block), and on `os-build/config.toml` with local state/socket paths. Negative controls (`max_connection_attempts = 0`; `expected_status = 200` next to `accepted_statuses`) are rejected.
- `cargo +1.93.1 test -p sozu-command-lib --all-features --locked`: 235 passed.
- `cargo +1.93.1 test -p sozu --bin sozu --locked`: 124 passed (including the `--load-balancing-policy` help tests).
- `cargo +nightly fmt --all --check` and `python3 .github/scripts/check_doc_citations.py --root . --base origin/main` are clean.



Signed-off-by: Florentin Dubois <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

H2 flood-protection defaults and RST accounting trip on legitimate traffic

1 participant