Repository navigation
fix(command): close the channel on an oversized declared frame length instead of wedging the session - #1438
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 22, 2026 09:09
FlorentinDUBOIS
force-pushed
the
fix/channel-oversized-delimiter-resync
branch
from
September 22, 2026 11:09
68d2abf to
917e0fe
Compare
…ceiling `try_read_delimited_message` rejected an oversized declared length with `ChannelError::MessageTooLarge` but left the eight-byte header at the head of `front_buf` and moved no readiness bit, unlike the sibling `MessageLengthUnderDelimiter` branch twelve lines below, which consumes the bogus delimiter precisely so the channel can re-sync. Nothing downstream compensated: `read_message_nonblocking` propagated the error with `?` and no log, `extract_messages` discarded it with a bare `Err(_)`, and `ClientSession::ready` / `WorkerSession::ready` close only on `readiness.is_error() || is_hup()`, which no parse error sets. The session stayed registered for the life of the process, re-parsing the same header on every later read, pinning its file descriptor and up to `max_command_buffer_size` of buffer, with nothing logged. The recovery is deliberately not the sibling's consume-and-re-sync. An oversized length can never be satisfied by a buffer bounded at `max_buffer_size`, and the bytes behind the header may be payload rather than a fresh delimiter, so dropping the header and re-framing on them would decode peer-chosen bytes as a control-plane request. It is now fatal for that peer: logged, then `readiness.insert(Ready::ERROR)`, which is the stance the write side already took for the identical condition (`is_transient_overflow`) and reuses the existing close path. The bit is inserted rather than assigned because on a worker's own channel `interest` holds only READABLE and WRITABLE, so `readiness()` masks ERROR away and nothing there reads `is_error()`; assigning would only clear WRITABLE and stall `Server::send_queue` until the next edge-triggered writability event. Closing is not a verdict on the peer. The two ends size their channels from their own `max_command_buffer_size`, so a peer configured higher emits such a frame through the ordinary write path while conforming perfectly: the two configurations shipped here already disagree tenfold, `bin/config.toml` at 163_840 against `os-build/config.toml`'s 1_638_400, so a `sozu ctl --config` pointed at one while the supervisor was started from the other overruns it on a large `LoadState`. Two binaries built with different `SOZU_CONFIG` defaults (`bin/build.rs`, `bin/src/util.rs`) diverge the same way; without `--config`, `sozu ctl` uses the configuration path baked in at build time and fails outright when none was, so it never falls back to a compiled buffer default. The receiving end still cannot complete or re-sync the frame, so it still closes -- before this change that connection wedged silently, which is worse -- but the `error!` line now names `max_command_buffer_size` and `command_buffer_size` on both ends instead of implying hostility. The branch's own comment claimed the rejection made "the read loop disconnect cleanly"; that half was false and is corrected, as is the same claim in doc/configure_admin_ops.md section 5.2. That section also said a dropped worker "observes the close as an EOF on its channel": it observes nothing. `handle_worker_close` calls `close_worker`, which sends SIGKILL, and `workers_to_spawn` replaces the process only when `worker_automatic_restart` is set. The same return-before-`consume` shape sat six lines below, on `Rx::decode`: a valid declared length with an undecodable payload -- eight good length bytes plus garbage, or protobuf skew between two builds -- wedged the session identically. That one now consumes and re-syncs instead of closing. Not because the boundary is proven: `message_len` is only range-checked, so consuming it can re-frame on bytes the sender never framed. Because the decode-success path four lines down already consumes that same peer-supplied length and re-frames on whatever follows, so the failure path now re-frames on exactly the bytes the success path already did, and closing only on the failing half would punish the case more likely to be honest protobuf skew. Its regression test is a channel-level one: `extract_messages` returns on the first `Err(_)` with the capacity unchanged, so a valid frame already pipelined behind the malformed one reaches the session only on its next readable event, and that residual is deliberately untested and unfixed here. The third instance, the `BufferFull` arm at the ceiling, is known-remaining and deliberately untouched, filed as #1436: its correct recovery is a `Buffer::shift` that makes room for a frame which can still complete, not a close, so closing there would drop a conforming peer over an internal buffer-management detail. Reachability: 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; the same parser also serves the master/worker socketpair, where a worker compromised through the traffic it proxies could wedge its supervisor session. Closes #1428 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
fix/channel-oversized-delimiter-resync
branch
from
September 22, 2026 12:11
917e0fe to
a7fe5cd
Compare
This was referenced Sep 22, 2026
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.
try_read_delimited_messagerejected an oversized declared length withChannelError::MessageTooLargebut left the eight-byte header at the head offront_bufand moved no readiness bit, unlike the siblingMessageLengthUnderDelimiterbranch twelve lines below, which consumes thebogus delimiter precisely so the channel can re-sync.
Nothing downstream compensated:
read_message_nonblockingpropagated theerror with
?and no log,extract_messagesdiscarded it with a bareErr(_), andClientSession::ready/WorkerSession::readyclose only onreadiness.is_error() || is_hup(), which no parse error sets. The sessionstayed registered for the life of the process, re-parsing the same header on
every later read, pinning its file descriptor and up to
max_command_buffer_sizeof buffer, with nothing logged.The recovery is deliberately not the sibling's consume-and-re-sync. An
oversized length can never be satisfied by a buffer bounded at
max_buffer_size, and the bytes behind the header may be payload rather thana fresh delimiter, so dropping the header and re-framing on them would decode
peer-chosen bytes as a control-plane request. It is now fatal for that peer:
logged, then
readiness.insert(Ready::ERROR), which is the stance the writeside already took for the identical condition (
is_transient_overflow) andreuses the existing close path. The bit is inserted rather than assigned
because on a worker's own channel
interestholds only READABLE and WRITABLE,so
readiness()masks ERROR away and nothing there readsis_error();assigning would only clear WRITABLE and stall
Server::send_queueuntil thenext edge-triggered writability event.
Closing is not a verdict on the peer. The two ends size their channels from
their own
max_command_buffer_size, so a peer configured higher emits such aframe through the ordinary write path while conforming perfectly: the two
configurations shipped here already disagree tenfold,
bin/config.tomlat163_840 against
os-build/config.toml's 1_638_400, so asozu ctl --configpointed at one while the supervisor was started from the other overruns it on
a large
LoadState. Two binaries built with differentSOZU_CONFIGdefaults(
bin/build.rs,bin/src/util.rs) diverge the same way; without--config,sozu ctluses the configuration path baked in at build time and failsoutright when none was, so it never falls back to a compiled buffer default.
The receiving end still cannot complete or re-sync the frame, so it still
closes -- before this change that connection wedged silently, which is worse
-- but the
error!line now namesmax_command_buffer_sizeandcommand_buffer_sizeon both ends instead of implying hostility.The branch's own comment claimed the rejection made "the read loop disconnect
cleanly"; that half was false and is corrected, as is the same claim in
doc/configure_admin_ops.md section 5.2. That section also said a dropped
worker "observes the close as an EOF on its channel": it observes nothing.
handle_worker_closecallsclose_worker, which sends SIGKILL, andworkers_to_spawnreplaces the process only whenworker_automatic_restartis set.
The same return-before-
consumeshape sat six lines below, onRx::decode: avalid declared length with an undecodable payload -- eight good length bytes
plus garbage, or protobuf skew between two builds -- wedged the session
identically. That one now consumes and re-syncs instead of closing. Not
because the boundary is proven:
message_lenis only range-checked, soconsuming it can re-frame on bytes the sender never framed. Because the
decode-success path four lines down already consumes that same peer-supplied
length and re-frames on whatever follows, so the failure path now re-frames on
exactly the bytes the success path already did, and closing only on the
failing half would punish the case more likely to be honest protobuf skew. Its
regression test is a channel-level one:
extract_messagesreturns on thefirst
Err(_)with the capacity unchanged, so a valid frame already pipelinedbehind the malformed one reaches the session only on its next readable event,
and that residual is deliberately untested and unfixed here.
The third instance, the
BufferFullarm at the ceiling, is known-remainingand deliberately untouched, filed as #1436: its correct recovery is a
Buffer::shiftthat makes room for a frame which can still complete, not aclose, so closing there would drop a conforming peer over an internal
buffer-management detail.
Reachability: 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; the same parser also serves the master/worker
socketpair, where a worker compromised through the traffic it proxies could
wedge its supervisor session.
Closes #1428
Signed-off-by: Florentin Dubois [email protected]