Skip to content

mux-h2: enqueue_rst has no per-insert cap, so a mass idle-timeout reap can grow pending_rst_streams past the bound check_invariants asserts #1413

Closed

Description

@FlorentinDUBOIS

ConnectionH2::cancel_timed_out_streams iterates the entire timed-out list and calls enqueue_rst
for every entry in one pass, deliberately discarding the flood-violation signal each call returns
(let _ = self.enqueue_rst(...), with a comment explaining why that is safe).

enqueue_rst_into has no per-insert cap. Unlike queue_window_update, which gates on
max_pending and returns a Dropped outcome, nothing stops pending_rst_streams growing past
MAX_PENDING_RST_STREAMS (200) within a single cancel_timed_out_streams call.

The cap that does exist is checked in the wrong place for this path.
flush_pending_control_frames's RST stage tests total_rst_streams_queued >= MAX_PENDING_RST_STREAMS
before its drain loop and short-circuits to GOAWAY(EnhanceYourCalm) — which correctly bounds the
drain, but does nothing about how large the queue got before anyone looked.

When it bites

max_concurrent_streams is operator-settable up to MAX_SAFE_CONCURRENT_STREAMS = 10,000. Raise it
above 200 and let enough streams idle-timeout or window-stall in the same sweep, and
pending_rst_streams.len() exceeds the bound that check_invariants asserts
(<= MAX_PENDING_RST_STREAMS + 1).

The assertion is only evaluated from handle_frame. cancel_timed_out_streams is reached from two
places: readable(), where a subsequent handle_frame will run and trip it in a debug build; and
Mux::timeout, where — against a fully silent peer, which is precisely the scenario that produces a
mass idle-timeout reap — handle_frame never runs at all.

So the two outcomes are: a debug/test/fuzz build panics on the next frame from that peer, or a release
build silently violates a documented invariant with an unbounded queue. Neither is the intended
behaviour of a cap.

Scope and provenance

Verified byte-for-byte identical at c1d28c8e and at every earlier revision inspected — this is
pre-existing, not introduced by the stream-table extraction that surfaced it. That changeset only moved
the data source of the timed-out list from two HashMaps to BTreeMaps; it did not touch the
cap-bypass shape.

It surfaced while answering a review question about whether ascending-stream-id RST ordering could
starve anyone. The fairness answer was no — a stream id is never reused, so being reaped first in a
pass carries no repeated disadvantage, unlike the WINDOW_UPDATE case where a stream competes for a
replenished resource across many rounds. But tracing "is the reap set unbounded?" led here.

Directions, not a proposal

Cap at the insert. Give enqueue_rst_into the same max_pending-gated Dropped outcome
queue_window_update has, so the queue cannot exceed its bound regardless of which caller is
enqueuing. This is the smaller change and makes the invariant structural.

Or check after the reap. Evaluate check_invariants at the end of cancel_timed_out_streams
rather than only from handle_frame, so the violation surfaces where it is caused rather than on the
next inbound frame — and so it surfaces at all on the Mux::timeout path.

The first is probably right, since the second only improves the diagnosis of a state that should not be
reachable. But the decision belongs with whoever owns the flood-detection budget: dropping RSTs on the
floor when the queue is full has its own protocol consequences, and EnhanceYourCalm may be the
correct answer at that point rather than silent truncation.

What was verified, and what was not

Verified by reading: the absence of a cap in enqueue_rst_into, the placement of the
total_rst_streams_queued check before the drain loop, the discarded return value in
cancel_timed_out_streams, the <= MAX_PENDING_RST_STREAMS + 1 bound in check_invariants, the two
call sites of cancel_timed_out_streams, and that handle_frame is the only caller of
check_invariants.

Not verified: no runtime reproduction was attempted. Reaching it needs a configuration with
max_concurrent_streams above 200 and a peer that opens enough streams and then goes silent; the
reasoning above says that is sufficient, but nobody has run it.

Activity

  1. added 6 commits that reference this issue on Sep 22, 2026
    4b3633a
    3527d67
    b8f8579
    1e474f8
    31626a4
    862c195
  2. added a commit that references this issue on Sep 23, 2026
    63e824b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions