Repository navigation
docs(command): record why the client channel ignores command_buffer_size - #1452
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 22, 2026 15:36
FlorentinDUBOIS
force-pushed
the
fix/command-socket-initial-capacity
branch
2 times, most recently
from
September 22, 2026 19:21
8595776 to
471a93a
Compare
`doc/configure.md` described `command_buffer_size` as "the buffer used by the main process to handle commands", and `bin/config.toml` / `os-build/config.toml` both introduced it as "size in bytes of the buffer used by the command socket protocol". All three are false for one of the three channel kinds the binary builds: `CommandHub::register_client` sizes every command-socket client channel at a literal `4096` and takes only its ceiling from `max_command_buffer_size`, while the supervisor<->worker channels (`bin/src/worker.rs`, `bin/src/upgrade.rs`, `CommandHub::from_upgrade_data`) and the CLI's own end of that same connection (`create_channel`, `bin/src/ctl/mod.rs`) all take `command_buffer_size`. No rationale for the literal was ever recorded, and that is checked rather than assumed: `f0ecc544` introduced it as the only commit of PR #1060, which carries zero inline review comments, zero issue comments, and a body that mentions neither `4096` nor a buffer nor a capacity. In that same commit `from_upgrade_data` fifty lines below already passed `command_buffer_size` -- the author had the configured values in hand and diverged here, plausibly for one page per connection. The `usize::MAX` ceiling it was paired with rules out a ceiling defence, not a sizing intent, and the CWE-770 comment that later appeared argues that ceiling only. Keep the value; record the argument. It is an address-space floor per client, and a resident one for every page a client touches: `Channel::new` allocates both buffers eagerly and `Buffer::with_capacity` is `vec![0; capacity]`, whose zero pages do not fault until written, while `try_shrink_front_buf` / `try_shrink_back_buf` never shrink below it -- growth above the floor IS released, the floor itself is not. Measured at 2000 clients holding two buffers each, under the jemalloc the binary links by default: wiring `command_buffer_size` through at its 1 MB built-in default costs 4737 MiB of address space and 9 MiB RSS untouched, rising to 3837 MiB RSS once every page is written; today's value costs 18 MiB and 17 MiB whether faulted or not. So the cheapest attack -- connect and send nothing -- buys address space rather than RSS, which still matters under RLIMIT_AS or strict overcommit. The resident cost does not arrive with the first byte either: it arrives page by page, as a client fills its buffers -- the same 2000 clients with 1 KiB touched in each buffer cost 28 MiB RSS at the 1 MB size, not 3837 MiB. Both multiply against `CommandHub::run`'s uncapped accept loop, and a client that never writes never reaches `command_allowed_uids`, which rejects at the request layer, after registration. Capping connections is the fix for that and is a separate change. What wiring the key through would buy is eight buffer doublings, and only on the read path: `Channel::grow_size` has exactly two call sites, `Channel::readable` and `try_read_delimited_message`, and both grow `front_buf`, so a request that fills the 2 MB default ceiling takes nine doublings from 4096 and one from 1 MB. A response saves none -- `write_delimited_message` doubles in a local variable and calls `back_buf.grow` once, one reallocation from either floor. The literal is now `CLIENT_CHANNEL_INITIAL_BUFFER_SIZE` carrying that argument and its measurements, and the pre-existing comment is marked as covering the ceiling alone. The documents naming the exception defer to the constant: `doc/configure.md`'s row says which channels the key sizes and what `Channel::new`'s clamp (#1416) does when `max_command_buffer_size` is set below 4096 -- the channel starts AT that ceiling with a `warn!`, never above it -- while keeping the row's existing sentence that the reverse pair is rejected at config load with `ConfigError::CommandBufferSizeExceedsMax`; its sibling row, which carried the same false phrasing and no default, is corrected in the same pass; `doc/configure_admin_ops.md` section 5.2 names the constant in place of "a hardcoded `4096`", and the paragraph under its table states that `ConfigBuilder::into_config` rejects an inverted pair at config load rather than advising operators to check the two values themselves, which #1416 made weaker than the code; and both shipped configuration files say the key does not reach the main process's end of the command socket. No behaviour change. `client_channel_initial_capacity_is_independent_of_command_buffer_size` pins the decision and fails with `left: 1000000 right: 4096` the moment the key is wired through. Its fixture sets both keys explicitly from `DEFAULT_COMMAND_BUFFER_SIZE` / `DEFAULT_MAX_COMMAND_BUFFER_SIZE` rather than copying their values, because `Config` derives `Default` and the built-in defaults are applied by `ConfigBuilder::into_config`, which the test never runs. `fuzz/README.md`'s construction-time note is corrected in the same pass: it still asserted that `Channel::new` "never validates `buffer_size <= max_buffer_size`" and that `config.rs` "does not validate `command_buffer_size <= max_command_buffer_size` either", both of which #1416 closed without touching that file, and its `command/src/channel.rs:528` line citation had rotted onto an unrelated timeout loop -- it now cites the symbol. `bin/src/command/LIFECYCLE.md` renumbers the two `server.rs` citations the inserted constant shifted, each re-derived from the construct its prose names rather than from an offset, as `check_doc_citations.py --base` requires. Closes #1430 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
fix/command-socket-initial-capacity
branch
from
September 22, 2026 21:22
471a93a to
83be7d4
Compare
This was referenced Sep 23, 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.
Closes #1430.
Documentation only — no behaviour change.
CLIENT_CHANNEL_INITIAL_BUFFER_SIZEkeeps the same4096the code has used sincef0ecc544; what changes is that the value now has a recorded argument and the documents around it stop being wrong.What was false
Four shipped documents said
command_buffer_sizesizes "the buffer used by the main process to handle commands". It does not size the main process's end of the command socket at all —CommandHub::register_clientpasses a literal that no configuration key reaches. The twoconfig.tomlfiles shipped in this repository carried the same sentence.Why the literal stays
Measured under jemalloc, exactly as
bin/src/main.rslinks it, at 2000 clients × 2 buffers:The address-space half is what carries the decision, not the resident half. 2.4 MiB per client is charged at
accept()— beforecommand_allowed_uidssees anything, for a peer that has sent zero bytes, against an accept loop with no cap. Raising this floor before a connection cap exists is the wrong order.Archaeology:
f0ecc544introducedChannel::new(stream, 4096, usize::MAX), fifty lines above the worker channel built from the configured values, withself.configin hand. A4096paired with an unbounded ceiling rules out a ceiling defence, not a sizing intent. PR #1060 carries zero inline comments, zero issue comments, and a body mentioning neither4096nor a buffer nor a capacity — so "no rationale was ever recorded" is a positive finding rather than an absence of one.Reviewed before opening, eight findings fixed
An adversarial review reproduced every measurement independently and found eight problems, three blocking. Each was reproduced again before being changed:
doc/configure.mdwarning about a latentdebug_assert!failure that fix(command): validate command_buffer_size against its maximum, and clamp the channel's initial buffer #1422's clamp had already made unreachable — and the natural conflict resolution would have silently deleted fix(command): validate command_buffer_size against its maximum, and clamp the channel's initial buffer #1422'sCommandBufferSizeExceedsMaxsentence. Both are now carried; the resolved row has a sentence-by-sentence accounting against main's version.grow_sizehas exactly two call sites, both onfront_buf;back_bufnever calls it.write_delimited_messagedoubles in a local and callsgrowonce, so for the response the sentence described, the saving is zero, not eight doublings. Nine doublings is right for the request path.Buffer::shrinktruncates andshrink_to_fits, which is a release. What is never released is the floor itself.statusrequest faults one page. Corrected with the 28 MiB measurement above.fuzz/README.mdstill asserted that neitherChannel::newnorconfig.rsvalidates the buffer pair. fix(command): validate command_buffer_size against its maximum, and clamp the channel's initial buffer #1422 closed both and never touched that file, which is outside the citation gate's surface. Its rottedchannel.rs:528citation was replaced with a symbol.Verification
Exit codes read directly, never through a pipe: build, clippy
-D warnings,fmt --check,test -p sozu(105 passed), citation gate against--root .and--base origin/main, andgit merge-treeagainstmain— all 0, conflict-free.The regression test was re-run red-then-green after the rebase, since the clamp now sits underneath it:
Its fixture sets both keys from the constants rather than their values, with an
assert_ne!guard making it self-invalidating.Note for reviewers
aws-lc-fips-sysfailed its build script twice during validation withmbx[warning]: build-script result was not stored: Not a directory (os error 20). Re-running the identical command on the identical tree gave exit 0 and compiled the crate. Same tree, both outcomes — the mbx build-script cache racing under concurrent load, not this changeset, which touches only Markdown, TOML comments and Rust doc comments. Flagged because it reads exactly like "my change broke the build".