Skip to content

docs(mux-h2): repoint H2DrainState field narration at h2_drain.rs and pin its arming invariant - #1461

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/drain-state-narration
Sep 23, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
fix/drain-state-narration

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Closes #1446.

#1425 moved the GOAWAY/graceful-drain state into lib/src/protocol/mux/h2_drain.rs
and made its fields private to that module. Five places still described those
fields as reachable from h2.rs, and one of them was not merely stale but wrong.

What was wrong

  • doc/architecture.md enumerated all five H2DrainState fields in prose, and the
    enumeration had already drifted into naming "pending RST streams" — which belong
    to H2StreamTable, not to H2DrainState.
  • LIFECYCLE.md described ConnectionH2::graceful_goaway as reading and writing
    H2DrainState fields. It does neither: its body is
    self.header_block_reassembly_in_progress() followed by
    match self.drain.begin_graceful_drain(...).
  • Two sites referred to a close_all_streams that exists nowhere. The real
    substitutes are handle_goaway_frame and prune_inactive_streams_while_closing,
    which each reach remove_dead_stream once per retired stream; neither clears
    the map
    , which is the property the prose was reaching for.

The fix removes the copy rather than correcting it

doc/architecture.md no longer enumerates fields. It now names the struct and the
module that owns them:

H2DrainState — RFC 9113 §6.8 GOAWAY/graceful-drain state machine; fields
private to h2_drain.rs

A restated five-field list is guaranteed to drift again; a role description
cannot. The sibling bullets do enumerate, so this is slightly off-register for the
file — that is a deliberate trade, not an oversight.

The invariant is now pinned, and the pin was seen red

LIFECYCLE.md quoted the tail of a debug_assert! message — "armed exactly
once, on the first call
" — as free prose, so it would drift silently if the
message were reworded. It is now a pinned block against
lib/src/protocol/mux/h2_drain.rs:234-237, copied verbatim from source, which
rule 4 compares byte-for-byte. Pin count 18 → 19.

Proof it detects anything: rewording the assert message to "on the very first
call" makes the gate exit 1 naming that block; restoring it returns exit 0. The
prose paraphrase that sat beside the quote was removed — a pin plus a
paraphrase is the same two-copies defect this changeset is about.

The claim the pin guards is exact: begin_graceful_drain arms started_at behind
debug_assert!(self.started_at.is_none(), ...), and the
GracefulDrainDecision::AlreadyDraining arm returns before the assignment.

Sweep, as the issue asked

The issue asks for hits read alongside hits changed, so both are recorded in the
commit body: 338 hits across 36 files read, 5 sites changed. (Note drain\.
is a literal field access — as a regex . it matches 933 hits across 52 files,
which is the wrong number to quote.) doc/h2_mux_internals.md:617,621 are left
alone; the issue puts them out of scope.

Two CHANGELOG sentences that the fixes themselves falsified were corrected in the
same pass: one still said the doc "names the five fields", and a blanket "reachable
by no rule" was no longer true once the pin put one of them under rule 4.

Verification

lib/src/protocol/mux/h2.rs is 8802 lines before and after — the comment edit
is deliberately -4/+4, so none of the 88 h2.rs citation groups below it move.

CI's own per-crate commands with
FLAGS='--no-default-features --features crypto-ring,opentelemetry,splice,simd':
cargo +nightly fmt --all -- --check, build, clippy -D warnings,
test -p sozu-lib (992 passed), test -p sozu , test -p sozu-e2e (445 passed),
both sozu-sim targets — all exit 0, zero failures.

Citation gate --root ., --base, and --self-test all exit 0; 241 citations,
369 test names, 19/19 pinned blocks verbatim. git merge-tree against main
exits 0 and the gate re-run inside the extracted merged tree also exits 0.
CHANGELOG: one entry added, no duplicates, no heading drift.

#1425 moved the RFC 9113 §6.8 GOAWAY/drain state machine into
h2_drain.rs and made all five H2DrainState fields private. Five
sentences outside that module still described them as reachable from
h2.rs; two were false rather than merely loose.

mux/LIFECYCLE.md §8.3 attributed `drain.started_at = Some(now)` to
ConnectionH2::graceful_goaway, which reads and writes none of the five
and delegates to H2DrainState::begin_graceful_drain. The passage now
names that method and PINS the debug_assert guarding the assignment as
a fenced quote of h2_drain.rs:234-237, so the invariant it encodes —
the budget arms exactly once, on the first call — is carried verbatim
by the source instead of paraphrased beside it. #1432 added that
mechanism for exactly this case; quoted unpinned, the sentence drifts
silently the moment the message is reworded. Seen red: rewording the
message to "on the very first call" exits 1 naming the block, and
restoring it exits 0.

The same attribution sat in production source: the RFC 9113 §6.8
comment guarding new peer-initiated streams said graceful_goaway sets
`drain.draining = true`. Only that mechanism clause changed; the
argument around it is correct and is kept. The comment keeps its exact
line count so the 88 h2.rs citations below it and the pinned code
blocks do not drift.

doc/h2_mux_internals.md's priority-cleanup list cited close_all_streams,
which has never existed under lib/ at any revision. ConnectionH2::goaway
is the nearest-sounding real function and is the wrong target: it
touches neither the prioriser nor the stream map. GOAWAY-time removal is
handle_goaway_frame plus prune_inactive_streams_while_closing, both
reaching remove_dead_stream once per retired stream, and neither clears
the map wholesale.

Two further hits from the same sweep: doc/lifetime_of_a_session.md
placed H2DrainState::draining in h2.rs, and doc/architecture.md credited
H2DrainState with "pending RST streams", which are H2StreamTable's
pending_rst_streams. That bullet names the struct's role and its module
and enumerates nothing: replacing a wrong five-field list with a right
one keeps the restated copy that drifted in the first place.

Sweep, read against c359eaf:

  git grep -En 'drain\.|draining|started_at|graceful_shutdown_deadline|peer_last_stream_id|initial_goaway_pending' \
      c359eaf -- lib/ doc/ | grep -v h2_drain.rs

338 hits across 36 files read. 3 of those hit lines changed, across 2
files: LIFECYCLE.md twice and h2.rs once. A 4th hit had the module path
beside it corrected (lifetime_of_a_session.md), and 2 further sites
carry no pattern token and so sit outside the hit set altogether —
h2_mux_internals.md's close_all_streams and architecture.md's
sub-struct bullet. Five sites in all.

The trailing `.` above is escaped and means a literal field access; as
an unescaped regex any-char the same sweep returns 933 hits across 52
files. doc/h2_mux_internals.md:617 and :621 are among the hits read and
deliberately left: they narrate module-internal state in the register
h2_drain.rs's own doc comments use and claim nothing about
reachability.

No rule in check_doc_citations.py reached any of these when written:
the drift rule compares a cited line at two revisions and these
documents do not modify h2.rs; the dead-name rule resolves test names
only; a code comment is in no rule. The pinned debug_assert is the one
that need not stay that way.

Refs: #1446
Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS force-pushed the fix/drain-state-narration branch from 160894d to b4dc2b6 Compare September 23, 2026 02:25
@FlorentinDUBOIS
FlorentinDUBOIS merged commit d560670 into main Sep 23, 2026
24 checks passed
@FlorentinDUBOIS
FlorentinDUBOIS deleted the fix/drain-state-narration branch September 23, 2026 03:44
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.

Three places still describe H2DrainState's fields as reachable from h2.rs, one of them wrongly

1 participant