Repository navigation
Rewrite commandserver with mio - #1060
Merged
Merged
Conversation
Keksoj
force-pushed
the
rewrite-commandserver-with-mio
branch
from
January 24, 2024 14:09
15ac78d to
0bedb9a
Compare
Wonshtrum
force-pushed
the
rewrite-commandserver-with-mio
branch
from
January 29, 2024 10:39
4d43f10 to
6f68cb7
Compare
Keksoj
force-pushed
the
rewrite-commandserver-with-mio
branch
3 times, most recently
from
January 30, 2024 10:42
7fe950a to
7ab1891
Compare
The multi-threaded, event-based architecture was too complicated and prevented introducing protobuf channels. The new CommandServer functions on the same principle as the proxy logic of Sōzu: listen to events with Mio in an event loop, dispatch the events accordingly by creating WorkerSessions, ClientSessions. This new CommandServer allows to create Tasks, that can scatter requests to all workers, gather their responses as the event loop goes, and invoke the task finish() when all responses are gathered. A worker whose unix socket is disconnected will be killed, and automatically restarted if configurated to. Conversely, if the main process dies, the orphaned workers will perform a hard stop. Sōzu channels used everywhere for communication with workers and clients. Automatic counting and respawning of workers, at each tick implement soft stop and hard stop improve CLI: - disable logging in CLI when displaying JSON - sort list of workers when displaying status error handling with thiserror remove obsolete documentation on managing workers remove unused dependencies: smol, futures, futures-lite, anyhow Co-Authored-By: Emmanuel BOSQUET <[email protected]>
Keksoj
force-pushed
the
rewrite-commandserver-with-mio
branch
from
January 30, 2024 14:14
7ab1891 to
f0ecc54
Compare
FlorentinDUBOIS
approved these changes
Jan 30, 2024
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 22, 2026
`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 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
added a commit
that referenced
this pull request
Sep 22, 2026
`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
added a commit
that referenced
this pull request
Sep 22, 2026
`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
added a commit
that referenced
this pull request
Sep 22, 2026
`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
added a commit
that referenced
this pull request
Sep 22, 2026
`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
added a commit
that referenced
this pull request
Sep 22, 2026
…ize (#1452) `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]>
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.
So that the protobuf channels of this PR can work:
#1000
expected_answersstoppingfield of Server should be better handled