Repository navigation
refactor(mux-h2): route the control-frame drain re-arms through signal_pending_write - #1491
Merged
Merged
Conversation
…ing_write `ConnectionH2::flush_pending_control_frames`'s WINDOW_UPDATE-drain and RST_STREAM-drain stages each ended their stalled branch with `self.readiness.event.insert(Ready::WRITABLE)`. No behaviour changes: `Ready::insert` cannot clear a neighbouring bit, so the two spellings are the same state transition. This is a missing guard, not a live defect (issue #1462). Both sites mean "pending write" in the helper's own sense, on three independent readings. They sit under `if self.socket.socket_wants_write()`, which is `Readiness::signal_pending_write`'s documented precondition verbatim — buffered data that will not generate a new epoll WRITABLE event. They run immediately after `flush_zero_to_socket` returned stalled, which means `update_readiness_after_write` has just REMOVED the WRITABLE event bit, so the insert is a re-signal after a stall cleared it rather than an epoll edge being recorded. And `ConnectionH2::ensure_tls_flushed` — called by the zero-buffer-resume stage a few lines above in the same function — is the identical gate and body, already spelled with the helper. What the hand-rolled spelling opted out of is the only mechanical statement of the `event`/`interest` rule: `signal_pending_write`'s two `debug_assert!`s, which prove it set WRITABLE and disturbed no other bit. It also opted out invisibly — `grep signal_pending_write` did not find these two, so an audit of "every place we signal a pending write" missed them. Production call sites go 13 to 15. Those assertions were inert here, measured rather than assumed: replacing each re-arm with a `panic!` and running the whole `sozu-lib` suite against the pre-image reports 1100 passed, 0 failed, neither panic observed. No test reached either stalled branch, so neither `debug_assert!` could ever execute on these paths. `a_stalled_window_update_drain_re_signals_the_writable_event` and `a_stalled_rst_stream_drain_re_signals_the_writable_event` now walk them. Neither test can see WHICH spelling a stage uses — by construction the two are indistinguishable from outside — so neither is offered as a regression test for the swap; what each detects is the re-arm going missing, which strands the serialized frame in `expect_write` with no further epoll edge coming, and each fails on its own assertion when its block is deleted. Reaching the stalled branch needs a non-empty `socket_write` answering `(0, WouldBlock)`, which a loopback socket with default buffers never does for 13 bytes of WINDOW_UPDATE, so `BackpressuredTlsSocket` gains a `write_script` mirroring its existing `vectored_script`; an empty script — the default — still delegates to the real socket, leaving every earlier test byte-for-byte unaffected. The three remaining hand-rolled `backend_readiness.event.insert(Ready::WRITABLE)` sites in `proxy_protocol::relay` are deliberately left alone: all three are inside `relay_test`, pairing an interest insert with an event insert to model "the event loop observed a WRITABLE edge on the backend" before calling `back_writable`. That is a fixture recording an epoll edge, not a session signalling buffered bytes, so the helper would state the wrong thing there. Production `RelayProxyProtocol` hand-rolls none. `git grep -n 'event.insert(Ready::WRITABLE)' -- lib/` finds two further hits and no more: the insert inside `signal_pending_write` itself, and the comment heading the two new tests, which names both spellings on purpose. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 24, 2026 03:05
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.
Closes #1462.
Two sites in
ConnectionH2::flush_pending_control_framesset the WRITABLE event bit by hand, bypassingReadiness::signal_pending_writeand the twodebug_assert!s that make it a guard rather than a spelling:There is no behaviour difference — both touch the
eventbit andinsertcannot clear a neighbour. The point is which guard was missing:signal_pending_writeis the one place theevent/interestdistinction is written down and asserted, and a site that bypasses it opts out invisibly, becausegrep signal_pending_writedoes not find it. An audit of "every place we signal a pending write" silently missed these two.Three independent readings confirm both sites mean "pending write" in the helper's sense rather than something narrower:
if self.socket.socket_wants_write()— the helper's documented precondition verbatim.flush_zero_to_socket()returned stalled, i.e.update_readiness_after_write(0, …)has just cleared WRITABLE. The insert is a re-signal after a stall, not an epoll edge being recorded.ConnectionH2::ensure_tls_flushed, called a few lines above in the same function, is byte-for-byte the same gate and body and is already spelled with the helper.Production call sites: 13 → 15.
The guard was inert, and that is why tests were added
The swap alone buys nothing if nothing walks the paths. Measured rather than assumed: replacing both sites with
panic!("REACHED-…-DRAIN"), confirming the literals compiled into the test binary viastrings, and running the whole suite gave 0 probe hits — no existing test reached either stalled branch, so neitherdebug_assert!could ever execute there.Re-measured after #1484 landed, since its six new tests drive the write path over a real
ConnectionH2<FrontRustls>and could plausibly have reached these sites: still 0 hits againstmainat9472cd96.So two tests were added to activate the guard:
a_stalled_window_update_drain_re_signals_the_writable_eventa_stalled_rst_stream_drain_re_signals_the_writable_eventEach was seen red on its own assertion independently. Deleting only the WINDOW_UPDATE re-arm fails the WU test —
the stalled WINDOW_UPDATE drain must re-signal the WRITABLE event … got Readiness { interest: -WEH, readiness: ---- }— while the RST test stays green; deleting only the RST re-arm gives the mirror.Reaching the stalled branch needs a non-empty
socket_writeanswering(0, WouldBlock), which a loopback socket never does for 13 bytes of WINDOW_UPDATE, soBackpressuredTlsSocketgains awrite_scriptmirroring its existingvectored_script. The empty script remains the default and delegates to the real socket, so every earlier test is byte-for-byte unaffected.The tests' own doc comments state plainly that they cannot distinguish the two spellings — they exist to make the assertion reachable, not to test the swap.
relay.rssweep — the issue asked, and it isunaffected×3lib/src/protocol/proxy_protocol/relay.rshas three more hand-rolled inserts onbackend_readiness. All three are past#[cfg(test)] mod relay_test, and all three pairinterest.insertwithevent.insertto model "the event loop observed a WRITABLE edge on the backend" before callingback_writable— their own comments say so.The helper is reachable there but would state the wrong thing: a fixture recording an observed epoll edge is not a session signalling buffered bytes, and
arm_writable's doc scopes it to production paths writing into sozu-owned buffers. ProductionRelayProxyProtocolhand-rolls none. Left unchanged, and no comments added — churn outside the issue.Repo-wide,
git grep -n 'event.insert(Ready::WRITABLE)' -- lib/now returns only the definition insidesignal_pending_writeitself, the comment heading the two new tests (which names both spellings deliberately), and those three fixtures.On red-then-green
No conventional red test is available and none was invented: the two spellings are the same state transition, so nothing can discriminate them. What is offered instead is the inertness measurement above, the two tests that make the assertion reachable, and each seen red under its own mutation.
An honest limitation, stated because it matters: the inverted-assert probe fires at the first
signal_pending_writecall in each test — enqueue-timearm_writable— not at the drain site. The panic-at-site probe is what locates it, and it confirms the helper returned there, so both itsdebug_assert!s executed and held.What a future regression looks like: someone re-spells a re-arm by hand (no test can catch that), or a new drain stage sets
eventwhile clearinginterest— whichsignal_pending_write's asserts catch in every debug build, and which now actually run because these two tests walk the paths.Verification
No test deleted or newly ignored, no assertion loosened, no lint escape, no
#[allow]added.doc/needs no change:doc/lifetime_of_a_session.mdandLIFECYCLE.mdstate the invariant generically, with no site enumeration and no call-site count.CHANGELOG.mdentry sits at the top of### 🔄 Changed; the insertion is pure — zero deleted lines against main's CHANGELOG.