Repository navigation
fix(mux): stop spinning on a refused TLS write when an H2 client stops reading - #1790
Merged
Merged
Conversation
…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
force-pushed
the
fix/mux-h2-tls-backpressure-spin
branch
from
October 2, 2026 01:18
8983307 to
81cc284
Compare
Signed-off-by: Florentin Dubois <[email protected]>
Signed-off-by: Florentin Dubois <[email protected]>
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1788
ConnectionH2::ensure_tls_flushedre-raised WRITABLE whenever rustls still held records, regardless of what the last socket write answered. After a write the kernel refused withWouldBlock,Mux::ready_innerre-ran the write pass on every inner iteration untilMAX_LOOP_ITERATIONS(http.infinite_loop.error). The same re-raise keptdrive_frontend_shutdown_iolooping 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:
SocketResult::Erroris not treated as refused here; fix(mux): stop spinning on a blocked TLS write when the client stops reading #1787 makes a TLS socket error mark the transport dead, which removes the pending records.connect_with_small_receive_bufferhelper appended toe2e/src/tests/h2_utils.rsis byte-identical in both, and the two branches merge cleanly.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) anda_refused_goaway_flush_waits_for_the_kernel_edge_then_closes(unit).