Repository navigation
fix(command): re-arm READABLE on the read failures a channel can parse past - #1464
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 23, 2026 03:00
…e past `Channel::read_message_nonblocking` (`command/src/channel.rs`) re-armed `Ready::READABLE` only on its `NothingRead` path; every error reached the caller through the `?` one line above it. `readable()` refuses to run at all while that bit is missing, and it drops the bit itself whenever it fills `front_buf` to a capacity it may not grow past -- correct backpressure, undone by whichever parse frees room. So a frame the parser rejected and then re-synchronised past re-aligned a buffer it could no longer refill, and the peer's next frame, still in the socket, was stranded on a session `wants_to_tick` (`bin/src/command/sessions.rs`) does not re-schedule for being merely readable. No hangup, no error, nothing logged. Two parse outcomes reach it. `MessageLengthUnderDelimiter` consumes exactly the eight bytes of a declared length no writer can emit for any payload, precisely so the stream re-aligns; `InvalidProtobufMessage` consumes the whole undecodable frame, which it has done since #1428. Both leave a channel that could parse the next frame if allowed to refill. The comment beside the first said the consume let "the channel re-sync on the peer's next frame", which was only ever true of the bytes already in `front_buf`; that clause is deleted rather than qualified, and what remains cites `rearms_readable` for the refill half instead of arguing with itself. The re-arm is per-variant, not a blanket one before the `?`: a socket that just failed a `read(2)`, or a peer this end has decided to drop, must not have its readability re-asserted. `rearms_readable` gives all fifteen `ChannelError` variants a disposition in a `match` with no wildcard arm, so a variant added later fails to compile rather than inheriting someone else's answer. Those three re-arm. `MessageTooLarge` does not: that branch consumes NOTHING -- it must not, since the bytes behind the header may be payload rather than a fresh delimiter and re-framing on them would decode peer-chosen bytes as a control-plane request -- so the buffer is not on a boundary and refilling only re-parses the same header, a busy loop rather than a recovery. The frame could not complete either way: a length above `max_buffer_size` does not fit a buffer bounded by `max_buffer_size`, however much more is read. Since #1428 the branch additionally marks `Ready::ERROR` so the supervisor drops the peer. `BufferFull` does not re-arm either: past #1436's compaction it means a buffer at the ceiling whose capacity cannot hold a length prefix, where `readable()` would read zero bytes and drop the bit again. Nor does `MismatchBufferSize`, an invariant violation whose slice fails identically on every retry. The remaining nine cannot reach this call site today and are dispositioned anyway. Half the defect sat in `extract_messages` (`bin/src/command/sessions.rs`), which returned on the very parse that re-synchronised the stream. `Buffer::consume` advances `position` and shifts only past `capacity / 2`, so retiring an eight-byte prefix moved neither the capacity nor the `available_space()` that the loop's two anchors watch. A failed parse that RETIRED bytes is now a third anchor and is checked first: it needs no spin guard and resets the compaction guard, because `consume` is the sole writer of `position`, so every `continue` retires at least one byte and the iteration count is bounded by what the peer writes -- exactly the bound the `Ok` arm has always had. Both halves were measured necessary. Against the branch point the regression test is red; with the re-arm alone it is red; with the anchor alone it is red; only together is it green. `client_session_delivers_the_frame_behind_a_malformed_length_prefix` is a session-level test -- a `ClientSession` driven through `extract_messages` -- because a channel-level one proves the channel re-syncs and says nothing about whether the session is ever ticked again. At `capacity == max_buffer_size == 64`: a 40-byte frame, an 8-byte prefix declaring 3, and a 46-byte frame, in ONE 94-byte write, so 64 bytes buffer and 30 stay in the socket while the peer waits for its response. It asserts that TWO frames come back, not which one: `ClientSession::ready` hands the caller `requests.pop()`, and which of the two that is, is a pre-existing pipelining question this changeset does not touch, so an assertion naming a frame would go red on a fix to `ready` that left #1445 correctly fixed. Counting is equally session-level, and the drained `available_data() == 0` beside it is a second, independent discriminator: 16 bytes were pending there before the fix, which is the issue's own measurement. A readiness bit is not asserted at all, since none reachable from a merely-readable channel would re-schedule that session. `malformed_payload_is_consumed_so_the_channel_resyncs`'s doc comment said the frame pipelined behind a malformed one "reaches the session only on its next readable event" and called that residual deliberately untested and unfixed. It now states what holds and points at the session-level test; the history is dropped rather than rebutted in place. The same sentence in the #1428 CHANGELOG entry is superseded by this changeset's entry rather than edited, so the two remain separable. Recorded, not fixed: re-arming on `InvalidProtobufMessage` keeps a peer that streams undecodable frames schedulable, and each such frame logs an `error!`, so this is a new log-volume surface -- bounded by the peer's bandwidth and strictly better than the wedge it replaces, but new, and the logging asymmetry it sits in is the one `doc/configure_admin_ops.md` §5.2 describes. Reachability is unchanged from #1428: the command socket is a unix socket chmod'd 0o600 and there is no control-plane TCP listener, so this is a robustness fix rather than a remotely triggerable one, though the same parser serves the master/worker socketpair. Only a malformed peer reaches it, which is why the severity is below #1436's -- but surviving a malformed peer is what a framing layer is for, and the comment beside this one claimed it already did. Closes #1445 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
fix/channel-readable-rearm
branch
from
September 23, 2026 04:19
cf0aea7 to
9c51573
Compare
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 #1445. Builds on #1449.
A malformed frame stranded socket bytes on an unschedulable session: the error
paths through
read_message_nonblockingskipped theReady::READABLEre-arm, soa channel that could have parsed past the bad frame never got another tick.
Both halves, and the harder one is checked first
Disposition —
command/src/channel.rs'srearms_readableis an exhaustivematchwith no wildcard over all 15ChannelErrorvariants, so a new variantis a compile error rather than a silent default:
NothingRead,MessageLengthUnderDelimiter,InvalidProtobufMessage→ re-armMessageTooLarge→ does not, and the reason holds at source: it consumesnothing and sets
Ready::ERRORNoByteToReadalready setsinterest = Ready::EMPTYplus HUP, andreadable()'sceiling path already removes
Ready::READABLE, so neither needs a new arm.Anchor —
bin/src/command/sessions.rsgainsif new_pending < old_pending { … continue; }ahead of both existing anchors, so a tick that consumed bytes keeps the session
schedulable regardless of which anchor would otherwise have fired.
read_message_nonblockingnow has no exit that bypasses the disposition.The regression test was seen red on both halves
It asserts the session-level property the issue names — that both frames are
delivered on one tick — rather than which request came back:
Both reds are the test's own assertion, not a production
debug_assert!. Thepanic line moving 1148 → 1153 is the five deleted anchor lines, which is what
confirms each break was the intended one.
An earlier draft asserted which request
ready()returned, which coupled thetest to
requests.pop()returning the last element — it would have gone red ifready()were ever corrected toremove(0), the real fix for the pipelining lossits own doc comment acknowledges. That assertion is gone;
available_data() == 0remains as a second, independent discriminator (16 bytes pending pre-fix, matching
the issue's measurement).
Single-sourcing
Three restatements of
wants_to_tick's predicate were removed in favour of namingthe symbol — it sits eleven lines away. The stale clause "so the channel can
re-sync on the peer's next frame" is deleted rather than rebutted: the
three-part recovery argument now lives once, in
rearms_readable's doc comment,and the consume site, the
extract_messagesanchor, the test docs and theCHANGELOG cite that symbol.
New surface worth naming
Re-arming on
InvalidProtobufMessagekeeps a peer that streams undecodable framesschedulable, and each one logs an
error!. Bounded by peer bandwidth and strictlybetter than the pre-fix wedge — but it is a new log-volume surface, and
doc/configure_admin_ops.mdalready discusses the logging asymmetry.Verification
CI's own per-crate commands,
--no-default-features --features crypto-ring,opentelemetry,splice,simd:cargo +nightly fmt --all -- --checkcargo build/cargo clippy --all-targets -- -D warningscargo test -p sozu-libcargo test -p sozusessions.rs)cargo test -p sozu-e2e -- --skip tests::fuzz_tests::sozu-simudp + tcp, withRUSTFLAGS='--cfg tokio_unstable'--ignoredcells (ci.yml:182-184)check_doc_citations.py --root ./--basegit merge-tree --write-tree origin/main <head>CHANGELOG: one entry added under
🐛 Fixed, no duplicates, no heading drift.Note the two
sozu-simcells build a 0-test binary withouttokio_unstableand exit 0 having run nothing — the counts above are with CI's own job env.