Repository navigation
WIP: fix/2356 respawn state channel — oversized state rides a temp file, not env - #2366
Merged
Merged
Conversation
…Refs #2356) A realized child (background &, coproc, process substitution) received the parent's shell state as execve arguments/environment. A single env string is capped at MAX_ARG_STRLEN (128 KiB) and the whole block at ARG_MAX, so a large function table wedged the spawn: the stamped __RUBASH_FORK_FN_SPANS entry alone was 205,593 bytes for 6,000 functions and execve failed E2BIG (the niubash#362 shape, pin issue_niubash_362::case_1 deterministically red on master). GNU has no such cap because it never serializes: a background command is realized by fork (execute_cmd.c:664 async -> execute_in_subshell, body at execute_cmd.c:1573; make_child, jobs.c), so the child simply inherits the parent's memory. Mechanism fix, applied at all four respawn sites (background, coproc, both process-substitution directions): env entries whose individual size or aggregate size would threaten execve now spill to a sibling temp file (the existing __RUBASH_CMD_FILE transport pattern); only a small __RUBASH_STATE_FILE pointer crosses in the environment. The child splices the entries back into its variable table during Executor::new, deletes the file, and strips the pointer. Any state payload of any size now crosses; no per-key special cases and no bigger buffers. Temp-write failure degrades to the previous inline behaviour instead of failing the spawn.
caomengxuan666
marked this pull request as ready for review
October 31, 2026 16:52
This was referenced Oct 31, 2026
SpookyWaste
pushed a commit
to SpookyWaste/rubash
that referenced
this pull request
Nov 12, 2026
unixwin#2423 adjudication outcome: the E2BIG defect is real at niubash's rubash pin 76f611d (reproduced exactly: line 6001 "Argument list too long", background output lost) but was already fixed on master by unixwin#2356 (0a0666e, PR unixwin#2366) — every fork-shaped respawn builder runs its composed environment through spill_respawn_env_entries, which moves oversized entries to the __RUBASH_STATE_FILE channel by size class, never by key. The pin predates that commit (not an ancestor); niu picks the fix up with the 1.5.0 pin bump. Master verified clean at 6000 function definitions across the seed shape plus background external/function, subshell, comsub, procsub, pipelines and coproc. The companion wait-status observation is refuted: bare `wait` returns 0 in GNU as well (builtins/wait.def no-arg path via jobs.c:2796 wait_for_background_pids; oracle 5.3.20-verified), and the failed launch itself reports status 1 with $! unset — GNU's fork-failure face, not a phantom success. These pins extend the existing issue_niubash_362 case_1 coverage (tests/regression.rs) to the crossing region (4800) and the sibling fork shapes (background function, procsub, coproc). Test-only; no product code changes. Refs unixwin#2423
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.
Refs #2356
Root cause
Realized children (background
&, coproc, process substitution) receive shell state as execve arguments/environment. A single env string is capped at MAX_ARG_STRLEN (131,072 B) and the block at ARG_MAX. For the niubash#362 shape (6,000 functions), the stamped__RUBASH_FORK_FN_SPANSentry alone is 205,593 bytes →execve = -1 E2BIG(strace-verified on master),hellonever printed; the pinissue_niubash_362::case_1_background_command_with_large_function_tableis deterministically red.GNU has no cap because it never serializes: background realization is
fork(execute_cmd.c:664 async →execute_in_subshell, body execute_cmd.c:1573;make_child, jobs.c) — the child inherits memory directly.Fix (mechanism, all four respawn sites)
src/invocation.rs(__RUBASH_STATE_FILEpointer key), sibling to the existing__RUBASH_CMD_FILEtransport that already carries oversized-csource.Executor::spill_respawn_env_entries: entries over 8 KiB individually, or enough largest entries to bring the inline block under 1 MiB in aggregate, move into a temp file; only the pointer crosses in env. Planted pointers are dropped (only the freshly minted one rides). Temp-write failure degrades to the previous all-inline behaviour.Executor::new_inner): pointer consumed and stripped, file read + deleted, entries spliced into the variable table with process-env mirroring before any downstream consumer.No key is special-cased and no buffer grew: any state payload of any size now crosses. Foreign/external children keep GNU's own env protocol (and its physical limits) by design — they are not realized shell children.
Verification (details in the cluster REPORT.md)
cargo check+cargo check --tests: rc 0.echo hello & wait): master → E2BIG,hellomissing, 11.2 s CPU; this branch →hello+large-fn-status:0, empty stderr, rc 0, 13.1 s CPU — byte-equal to the GNU oracle output.Do not merge from this description alone — the pin re-run under the scrubbed-fd protocol is the gate.