Repository navigation
WIP: fix #2521 carrier restore crossing - #2559
Conversation
…livery contract Refs #2521 Regression of the #2333 carrier restore, bisected: the pins in tests/issue2333_inherited_carrier_restore_regressions.rs pass 7/7 at 7a66413 (PR #2470) and fail 5/7 at e6ccbf1 (PR #2471). The regressing commit is ec40a88 ("deliver ambient std-stream fds across child spawns"), which added an occupancy probe to the startup restore: "prefer the stamped descriptor when it is open in this child". GNU semantics (the spec): a forked child inherits the parent's whole descriptor table, each descriptor keeping its own open file description (bash-5.3 execute_cmd.c, execute_in_subshell, :1576). rubash materializes that inheritance through spawn-time pins plus the __RUBASH_FD_HANDLE_<slot> stamps, and the restore must reconstruct each slot from the descriptor the TRANSPORT actually delivered: - pin transports (external ambient pass, input/output procsub, coproc): the carrier is pinned AT the slot fd; the stamp records the PARENT's descriptor number, which designates nothing in the child (the #2333 at-slot adoption rule, 8105a63). - whitelist respawn transport (fd::spawn_whitelisted, sole caller execute_background_ast_command): each extra crosses AT its stamped number; the child's raw slot fd can be its own read-only script file (the #2212 EBADF case ec40a88 was protecting). The occupancy probe cannot tell these apart: the pin pass stages each carrier above the ceiling and dup2s it onto its slot, leaving the staging sources open — so in a pin-delivered child the stamped number of slot N is open and holds a leftover copy of ANOTHER slot's carrier. The probe adopted those leftovers and rotated every carrier by one (n3 got body-four, n4 got the already-consumed carrier: EOF). Fix by mechanism: the spawner declares its delivery contract and the restore obeys the declaration instead of inferring it from fd occupancy. execute_background_ast_command — the only whitelist spawner — now sets __RUBASH_FD_AT_STAMPED=1 in the child env; the startup transport-key consumption removes it (it never surfaces as a shell variable or rides the env mirror) and the restore adopts the stamped descriptor only when the key declared at-stamped delivery. The fcntl occupancy probe is deleted; the #2333 at-slot rule is unchanged for every pin transport, and the Windows path (stamped value verbatim) is untouched. Verification (build slot, scrubbed_cargo.py cargo test): issue2333_inherited_carrier_restore_regressions 7/7 (was 2/7), issue2212_bats_remainder_regressions 15/15, issue2256_devfd_fresh_open_regressions 25/25, issue2479_devfd_reopen_cursor_regressions 8/8, issue2502_pipeline_alias_delivery_regressions 6/6, issue2476_born_closed_stdout_regressions 7/7, issue2484_stage_fd3_delivery 4/4.
99f9a5a to
d2a1600
Compare
|
[win-acceptance] #2559 PASS — Environment: Windows 10 19045 real machine, MSVC Rust debug build of master b41e8b6 (contains this merge), oracle |
Refs #2521
Regression
The #2333 child startup-restore carrier crossing is back: a child that
inherits two or more heredoc/file carriers reads each carrier's content
from the NEXT carrier's descriptor (n3 gets body-four, n4 gets EOF).
Bisected with
tests/issue2333_inherited_carrier_restore_regressions.rs:7/7 at
7a664134(PR #2470), 5 red ate6ccbf14(PR #2471). Regressingcommit: ec40a88 ("deliver ambient std-stream fds across child
spawns"), which added an occupancy probe to the startup restore:
"prefer the stamped descriptor when it is open in this child".
Root cause
GNU: a forked child inherits the parent's whole descriptor table, each
descriptor keeping its own open file description (bash-5.3
execute_cmd.c,execute_in_subshell, :1576). rubash materializes thatinheritance via spawn-time pins +
__RUBASH_FD_HANDLE_<slot>stamps,and two transports give the stamp different meanings:
coproc): carrier pinned AT the slot fd; the stamp is the PARENT's
descriptor number ([bug] 子壳继承 ≥2 个 ambient heredoc 载体时启动恢复串线(#2292 面残差) #2333 at-slot adoption, 8105a63).
fd::spawn_whitelisted, sole callerexecute_background_ast_command): extras cross AT their stampednumbers; the raw slot fd can be the child's own read-only script file
([ecosuite] bats-core own suite: setup/teardown + file-evaluation machinery divergences (7 files, named tests) #2212 EBADF — what ec40a88 was protecting).
The probe cannot distinguish them: the pin pass stages each carrier
above the ceiling and dup2s it onto its slot, leaving staging sources
open, so in a pin-delivered child the stamped number of slot N is open
and holds a leftover copy of ANOTHER slot's carrier. The probe adopted
the leftovers — a +1 rotation of every carrier.
Fix
The spawner declares its delivery contract; the restore obeys the
declaration instead of inferring from fd occupancy:
execute_background_ast_command(the only whitelist spawner) sets__RUBASH_FD_AT_STAMPED=1in the child env.variable, never in the env mirror) and the restore adopts the stamped
descriptor only under at-stamped declaration. The
fcntloccupancyprobe is deleted; the [bug] 子壳继承 ≥2 个 ambient heredoc 载体时启动恢复串线(#2292 面残差) #2333 at-slot rule is unchanged for all pin
transports; the Windows path (stamped value verbatim) is untouched.
Verification (build slot, scrubbed_cargo.py cargo test)
Full write-up:
~/workspace/rubash-wave-20261102/w1-carrier/REPORT.md(cluster workspace).