Skip to content

No test instantiates ConnectionH2<FrontRustls>, so 15 socket_wants_write branches including the truncation vector are unexercised #1454

Closed

Description

@FlorentinDUBOIS

No test anywhere instantiates ConnectionH2<FrontRustls>. SocketHandler::socket_wants_write() returns the trait default false on mio::TcpStream and SessionTcpStream, and FrontRustls is the only override (lib/src/socket.rs:1141). So every branch gated on that method takes the false arm in every test that exists.

Measured at cd904815: 15 sites in lib/src/protocol/mux/h2.rs query socket_wants_write() — 1240, 2633, 2734, 2945, 3008, 3038, 3044, 3077, 3079, 4074, 4115, 4152, 5558, 5573, 5615. None has ever run against a handler that can answer true.

Found while inventorying Front coupling for the H2 sans-io extraction; the extraction exposed it rather than caused it.

Why this is worse than an ordinary coverage gap

The branch class it leaves untested is the TLS truncation vector. The comment above one of these sites says so in the repository's own words: // backpressure (HAProxy chain), this is the primary truncation vector.

The shape at that site:

if self.socket.socket_wants_write() {
    self.socket.socket_write(&[]);
    if self.socket.socket_wants_write() {

The middle call discards both size and status — whether the kernel accepted the flush is inferred only from the second query, so the two questions are fused through the handler's internal state rather than through the returned SocketResult. That reconstruction is exactly what a FrontRustls fixture would exercise and what nothing currently does.

There are three structurally near-identical triples in the file (3077-3079, 3038-3044, 4152-4153). A test written against the wrong one would look correct and prove nothing about the vector.

Asked for

A ConnectionH2<FrontRustls> fixture, and coverage of the socket_wants_write() == true arm for the sites above — at minimum the three triples and force_disconnect's server arm (5573).

Each test seen red first. For a backpressure branch the meaningful red is a fault-injected handler that reports true on the first query and false on the second (flush accepted) versus true on both (still buffered), with an assertion that the connection does not truncate in either case. A test that only exercises the false path passes today and would pass against a broken implementation — which is the current situation.

State in the changeset that this is the first coverage these branches have had. A reader finding tests there later will otherwise assume the class was always covered and that a regression is new.

Do not

Do not close this by asserting the false path more thoroughly — that is the path that already works. Do not mock socket_wants_write() on a type that is not FrontRustls: the point is that the only production implementation which can return true is the TLS one, and a fixture that fakes it on a TCP handler tests the fake.

Activity

  1. FlorentinDUBOIS commented on Sep 23, 2026

    @FlorentinDUBOIS
    CollaboratorAuthor

    Decision: deferred until the H2 sans-io extraction completes

    The gap and its severity are accepted as stated — these 15 branches include the truncation vector,
    and the middle socket_write(&[]) discarding both size and status is exactly the reconstruction
    a FrontRustls fixture would exercise.

    Deferred purely on sequencing: the sans-io extraction is moving these sites right now, and the
    write_streams inversion still to come rewrites the write path they sit on. Tests written against
    the current arrangement would be rewritten before they ever caught anything.

    Two things to carry forward when it is picked up:

    • Write the fixture against behaviour, not line numbers — a fault-injected handler reporting
      true then false (flush accepted) versus true twice (still buffered), asserting the connection
      does not truncate in either case. That formulation survives the sites moving.
    • Three structurally near-identical triples exist in the file. A test written against the wrong one
      looks correct and proves nothing about the vector, so name which triple each test targets.

    Until then this issue is the record that the class is uncovered; nothing should read the absence of
    tests there as evidence the branches were ever exercised.

  2. FlorentinDUBOIS commented on Sep 23, 2026

    @FlorentinDUBOIS
    CollaboratorAuthor

    Decision revised: the fixture lands BEFORE the write_streams inversion

    This supersedes the deferral above. That decision was taken on a cost framing — "the sites are
    moving, writing the tests afterwards avoids rewriting them" — which was the wrong question.

    The right one: the write_streams inversion is the rewrite of these fifteen sites, roughly 1100
    insertions on the hot write path. And update_readiness (lib/src/protocol/mux/mod.rs:380-404)
    returns stalled only when size == 0, so size > 0 && status == WouldBlock clears the event bit,
    returns not-stalled, and the while !kawa.out.is_empty() loop issues another socket_write_vectored.
    A yield protocol that treats status != Continue as a terminator therefore drops that second write —
    and passes every test that exists, because FrontRustls is the only handler that can answer true
    to socket_wants_write() and nothing instantiates it.

    So a fixture written after the inversion is written against whatever the inversion produced,
    including that bug. Written before, it goes red against the pre-image and constrains the rewrite
    instead of describing it. That is the only window in which the truncation vector has an oracle
    independent of the change being made.

    Carried forward from the earlier comment, unchanged:

    • Write it against behaviour, not line numbers — a fault-injected handler reporting true then
      false (flush accepted) versus true twice (still buffered), asserting no truncation either way.
      That formulation survives the sites moving.
    • Three structurally near-identical triples exist. Name which one each test targets; a test written
      against the wrong one looks correct and proves nothing about the vector.
  3. FlorentinDUBOIS commented on Sep 23, 2026

    @FlorentinDUBOIS
    CollaboratorAuthor

    Partial coverage landed, and a correction to this issue's premise

    Measured on c9dd662a, two things in the description above are no longer accurate.

    The site list. h2.rs carries 16 socket_wants_write() query sites, not 15 — this issue
    omits initiate_close_notify and has_pending_write. There are 2 more in shared.rs
    (drain_tls_close_notify). Of those 18, two are log arguments rather than branches
    (flush_zero_to_socket's #[cfg(debug_assertions)] trace!, and force_disconnect's client arm), so
    there is nothing to cover at either.

    The three triples, resolved. h2.rs has four socket_write(&[]) sites. Three are the
    query / write(&[]) / query shape where the middle call discards both size and status:
    finalize_write, writable's GoAway arm, and writable's preamble paired with the Error arm. The
    fourth, flush_zero_buffer, is not a triple — it keeps the returned status instead of
    re-querying. That distinction was not in the original analysis and it matters, because a test written
    against the fourth would prove nothing about the vector.

    Where the queries live after the sans-io extraction. h2_transmit.rs and h2_control_tx.rs
    contain zero, and every socket_wants_write() in h2_close.rs is //! or /// prose. The
    extraction moved the decisions — now pure fn(bool) -> CloseAction / FinalizeAction — and left
    the live queries at the edge in h2.rs. That is the intended shape, not a gap.

    What was uncovered, and why it could not be reached

    BackpressuredTlsSocket (added by the step-9 stack) already models rustls-over-a-blocked-kernel as
    state and reaches two of the three triples in full. What it structurally could not do is script
    (size, status): it delegated socket_write_vectored to a real loopback mio::net::TcpStream, and a
    blocked kernel answers (0, WouldBlock) — never (size > 0, WouldBlock).

    So the branch that matters most had no oracle against production code at all:

    • update_readiness_after_write — which holds the "stalled iff size == 0" rule — had zero
      direct tests.
    • flush_stream_out's loop was covered only by a loop reimplemented inside h2_transmit's own test
      module
      , which calls neither flush_stream_out nor update_readiness_after_write, and whose
      WritePlan carries an accept count and no SocketResult at all. A mirror cannot constrain what
      it mirrors, and that plan could not express the pair in the first place.
    • Nothing called ConnectionH2::force_disconnect() — the site this issue names explicitly.
      h2_close::force_disconnect_action is exhaustively tabled over its two booleans, but a table is not
      its caller.

    Deviation from this issue's literal guidance, recorded deliberately

    This issue says "do not mock socket_wants_write() on a type that is not FrontRustls".
    BackpressuredTlsSocket is exactly such a mock, and the coverage extends it rather than building a
    ConnectionH2<FrontRustls> fixture.

    The reason: (size > 0, WouldBlock) is structurally a FrontRustls return shape — buffered_size
    accumulates from session.writer().write(..) while can_write goes false when write_tls blocks
    against the kernel, so two independent quantities share one return value. The script reproduces a real
    handler's contract one layer down rather than inventing one, and an empty script delegates exactly as
    before, leaving the pre-existing tests byte-for-byte unaffected.

    What that does not buy stays open: these tests prove the loop logic, not the real FrontRustls
    wiring. A ConnectionH2<FrontRustls> fixture remains worth building for the wiring, and this issue is
    the record that it does not exist yet.

    Still uncovered, with reasons rather than as a backlog

    initiate_close_notify (cheap, but not on the write-inversion path); flush_pending_control_frames
    ×2 (needs queued control_tx frames and a stalled flush_zero_to_socket); error_close_action's
    caller (needs H2State::Error — the fixture is already parametrised on state, so this is a one-line
    extension); has_pending_write's third disjunct; flush_zero_buffer; close; and
    shared.rs's two, which nothing currently calls.

  4. FlorentinDUBOIS commented on Sep 23, 2026

    @FlorentinDUBOIS
    CollaboratorAuthor

    Where the coverage still is not, measured by panic probe

    The fixture branch adds five tests that drive flush_stream_out directly. Before opening its PR I had the branch reviewed adversarially, and the reviewer probed the suite by planting a panic! inside production and reading which tests fell over. That is a sharper instrument than reading call graphs, and it found something worth writing down here rather than in a PR description.

    flush_stream_out has exactly one producer of FlushOutcome::Stalled and two consumers. On c9dd662a:

    $ grep -n 'FlushOutcome::Stalled' lib/src/protocol/mux/h2.rs
    2266:            if outcome == FlushOutcome::Stalled {      # consumer: resume path
    2597:            if outcome == FlushOutcome::Stalled {      # consumer: main write loop
    2753:                return FlushOutcome::Stalled;          # producer
    

    I verified that enumeration myself; all three are production (#[cfg(test)] mod tests opens at 6332).

    Both consumers are reached by zero tests, before and after the fixture branch.

    • h2.rs:2266 — the resume path's if outcome == FlushOutcome::Stalled { return MuxResult::Continue; }. Its whole call site is flush_stream_out at h2.rs:2235 with debug_site = 2, and the probe found no test at all enters debug_site = 2.
    • h2.rs:2597 — the main loop's set_expect_write(Some(...)); break 'outer;.

    A panic! planted where flush_stream_out returns Stalled (h2.rs:2753) gives 1082 passed; 1 failed, the single reacher being the new a_write_that_moves_no_bytes_stalls_the_pass, which calls the associated function directly. Nothing arrives there through writable().

    Separately, a panic! at the top of flush_stream_out's while body shows exactly five of 1083 tests ever enter that loop — the three new direct callers plus one_write_pass_prefixes_its_first_header_block_only_and_shares_one_encoder and its quickcheck sibling, both of which run over a ConnectionH2<mio::net::TcpStream> and therefore only ever see (size, Continue) from a loopback socket.

    Why this matters for the write_streams inversion

    The five new tests pin the inside of the flush loop. The inversion lifts the round-again decision out of it. Three shapes it can take that the new tests cannot see:

    1. flush_stream_out keeps its signature but stops being the loop. If the round-again decision moves up into write_streams and flush_stream_out becomes a single-shot helper, all five tests stay green against a vestigial function. A signature change would break compilation and force a revisit — identical signature with a hoisted terminator is the dangerous case.
    2. A pass terminator keyed on status rather than on outcome. Breaking 'outer because the socket reported WouldBlock during one stream's flush defers every later stream's queued bytes. Combined with h2_close::finalize_action, which suppresses the finalize flush entirely once socket_wants_write() is true (h2.rs:2897-2900), the pass can end with Ready::WRITABLE withdrawn and no external trigger. That is a hang, not a truncation, and no sozu-lib unit test would move.
    3. total_bytes_written mis-accumulation at h2.rs:2595. It feeds finalize_write's bytes_written_this_pass, which selects invariant-16 RetainPendingBack over Quiesce. The new tests pin flush_stream_out's own bytes_written, not write_streams's fold of it; a (size > 0, WouldBlock) round accounted as zero flips Quiesce and strips WRITABLE with queued back bytes still on the stream.

    The step that would close it

    h2.rs:7550-7556 already concedes the boundary: reaching these sites through writable() needs a stream carrying response bytes through the scheduler, and no fixture built one. The branch's new response_stream_with_out_blocks helper is such a stream — it is just handed straight to flush_stream_out instead of being installed in a Context and driven through writable(). Installing it is one step, and it is the step that turns sites 2266 and 2597 from unreachable into asserted.

    I am not doing that in the fixture branch: it is a different fixture with a different failure mode, and holding the branch open for it delays the work it exists to constrain. Filing it here so the inversion is reviewed against a known blind spot rather than an assumed-covered one.

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