Skip to content

fix(mux): stop spinning on a refused TLS write when an H2 client stops reading - #1790

Merged
FlorentinDUBOIS merged 3 commits into
mainfrom
fix/mux-h2-tls-backpressure-spin
Oct 2, 2026
Merged

FlorentinDUBOIS merged 3 commits into
mainfrom
fix/mux-h2-tls-backpressure-spin

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Fixes #1788

ConnectionH2::ensure_tls_flushed re-raised WRITABLE whenever rustls still held records, regardless of what the last socket write answered. After a write the kernel refused with WouldBlock, Mux::ready_inner re-ran the write pass on every inner iteration until MAX_LOOP_ITERATIONS (http.infinite_loop.error). The same re-raise kept drive_frontend_shutdown_io looping on a backpressured TLS H2 session.

The connection now records whether the latest socket write of a pass answered WouldBlock; if so, no synthetic WRITABLE is raised and the event is consumed (also on the empty-buffer TLS flushes, whose status was discarded). The kernel's next writable edge resumes the flush. Close decisions (h2_close) still read whether rustls holds records, so GOAWAY/close_notify records are flushed before the connection closes.

Notes:

Tests: test_tls_h2_stalled_reader_does_not_exhaust_loop_budget (e2e, red on main: 2 loop-budget errors; green: 0, full 32 MiB body received once the client reads again) and a_refused_goaway_flush_waits_for_the_kernel_edge_then_closes (unit).

…s reading

ConnectionH2::ensure_tls_flushed re-raised the WRITABLE event whenever
rustls still held records, whatever the last socket write answered. After
a write the kernel refused with WouldBlock (the stalled control-frame
flush, finalize_write_after_flush, the GoAway and Error close arms),
Mux::ready_inner ran the write pass again on every inner iteration until
MAX_LOOP_ITERATIONS counted http.infinite_loop.error.

The connection now records whether the latest socket write of the pass
answered WouldBlock and then leaves WRITABLE to the kernel's next edge,
consuming the event as update_readiness_after_write does, including on
the empty-buffer TLS flushes whose status nothing read. Close decisions
still read whether rustls holds records, so a connection keeps WRITABLE
interest and stays open until the kernel edge flushes them.

The control-frame drain tests now stall on a write the kernel did not
refuse, and the real-rustls GoAway/Error tests assert that the refused
pass queues no event before the edge-triggered pass flushes and closes.

Fixes #1788

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS force-pushed the fix/mux-h2-tls-backpressure-spin branch from 8983307 to 81cc284 Compare October 2, 2026 01:18
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 0f3ef71 into main Oct 2, 2026
23 checks passed
FlorentinDUBOIS added a commit that referenced this pull request Oct 2, 2026
…n every TLS write error (#1795)

Fixes #1794

Follow-up to #1787 and #1790.

- `flush_tls` retries a write interrupted by `EINTR` (as `proxy_protocol/relay.rs` and `udp.rs` do) instead of answering `Error` and marking the channel dead. `flush_tls` is now generic over `io::Write` so the retry is unit-tested.
- `FrontRustls::socket_write` and `socket_write_vectored` set `peer_reset` on every `SocketResult::Error` they return (one assignment per function, replacing the five per-arm ones). The rustls writer failure and the loop-budget arms returned `Error` without it, so the records kept reading as pending and the session waited for its timeout. Those two arms cannot be driven from a test with rustls 0.23 (its plaintext writer does not fail, and every loop iteration makes progress or stops); they are covered by the shared assignment.
- Tests, each seen red with its line removed: one per TLS write path (empty flush, vectored whole write, vectored partial write, empty vectored flush), the EINTR retry, and on H2 `a_refused_control_frame_drain_leaves_writable_to_the_kernel` (`(0, WouldBlock)` sibling of the two control-drain tests, red without the refusal record in `consume_output_flush`) and `a_refused_stream_write_leaves_writable_to_the_kernel` (red without the one in `handle_write`, which the `SkipFlush` finalize path depends on).
- Docs: `a_rustls_frontend_in_{error_state,goaway}_re_arms_until_its_records_drain` renamed to `..._stays_open_until_its_records_drain`; the CHANGELOG/LIFECYCLE sentence about those tests now says the test drains the records and the next pass closes; LIFECYCLE item 12 covers `ConnectionH2`; the `force_disconnect_over_a_real_rustls_frontend_*` assertion explains why it still re-signals (no refused write recorded in a pass); `peer_reset` and `doc/lifetime_of_a_session.md` no longer say "any other error but WouldBlock".



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

Bring in the updated base branch, which itself now carries origin/main.

Resolve the conflict in `H2Shell::flush_tls_records`
(lib/src/protocol/mux/h2.rs): main records every write status through
`self.core.note_write_status(status)` (#1790), and this
branch through `self.record_write(status)`. Keep both, in that order:
the first drops a refused flush's WRITABLE edge, the second remembers a
failed write to the client.

Re-pin the `readable()`, `writable()` and `flush_output_to_socket()`
code blocks of doc/h2_mux_internals.md to their lines in the merged
h2.rs.

Separate this branch's CHANGELOG entry from the previous one with a
blank line, as between every other entry.

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.

fix(mux): http.infinite_loop.error increments when a TLS H2 client stops reading a large response

1 participant