Skip to content

docs(command): record why the client channel ignores command_buffer_size - #1452

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/command-socket-initial-capacity
Sep 22, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
fix/command-socket-initial-capacity

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Closes #1430.

Documentation only — no behaviour change. CLIENT_CHANNEL_INITIAL_BUFFER_SIZE keeps the same 4096 the code has used since f0ecc544; 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_size sizes "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_client passes a literal that no configuration key reaches. The two config.toml files shipped in this repository carried the same sentence.

Why the literal stays

Measured under jemalloc, exactly as bin/src/main.rs links it, at 2000 clients × 2 buffers:

case VmSize Δ VmRSS Δ
1 MB × 4000, untouched 4737.0 MiB 8.6 MiB
1 MB × 4000, 1 KiB touched each 4737.0 MiB 28.1 MiB
1 MB × 4000, fully written 4737.0 MiB 3838.7 MiB
4096 × 4000, untouched 18.0 MiB 16.3 MiB

The address-space half is what carries the decision, not the resident half. 2.4 MiB per client is charged at accept() — before command_allowed_uids sees 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: f0ecc544 introduced Channel::new(stream, 4096, usize::MAX), fifty lines above the worker channel built from the configured values, with self.config in hand. A 4096 paired 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 neither 4096 nor 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:

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, and git merge-tree against main — all 0, conflict-free.

The regression test was re-run red-then-green after the rebase, since the clamp now sits underneath it:

assertion `left == right` failed: client channel front buffer must start at the per-client floor
  left: 1000000
 right: 4096

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-sys failed its build script twice during validation with mbx[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".

@FlorentinDUBOIS
FlorentinDUBOIS force-pushed the fix/command-socket-initial-capacity branch 2 times, most recently from 8595776 to 471a93a Compare September 22, 2026 19:21
`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
FlorentinDUBOIS force-pushed the fix/command-socket-initial-capacity branch from 471a93a to 83be7d4 Compare September 22, 2026 21:22
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 5989080 into main Sep 22, 2026
24 checks passed
@FlorentinDUBOIS
FlorentinDUBOIS deleted the fix/command-socket-initial-capacity branch September 22, 2026 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

command: command_buffer_size never reaches the command-socket client channel, which is built at a hardcoded 4096

1 participant