Repository navigation
fix(executor): respawned fork-children die silently on EPIPE like GNU SIGPIPE (Refs #3475) - #3753
Merged
Merged
Conversation
… SIGPIPE (Refs #3475) Disclosed as Windows platform debt during the #3475 coproc rework: `coproc <<HD cat` intermittently printed `case.sh: line 1: Broken pipe` when the parent exited (or retired the coproc read end via `exec {COPROC[0]}<&-`) before the child's output write landed. The fault was NOT the pipe lifetime — GNU models the coproc body as a fork, and a forked child restores every signal's startup disposition (execute_cmd.c:1670 -> trap.c:1480 reset_signal_handlers), so SIGPIPE is SIG_DFL there and a write that meets a pipe with no readers kills the child silently with status 141. rubash respawns fork-shaped bodies (async `&`, coproc, both process-substitution forms) as `rubash -c` children marked by the validated RESPawned_CHILD provenance (init.rs), but the child's EPIPE still ran the MAIN shell's write-failure path (report_io_error_routed) and printed `Broken pipe` — the #440 model, which is only correct for the main shell whose SIGPIPE stays SIG_IGN. Mechanism fix at the two seams where a child's EPIPE verdict unwinds: - report_io_error_routed (ast_exec.rs): a validated respawn child's EPIPE returns ExecuteError::BrokenPipe instead of the main-shell diagnostic; the -c driver maps that arm to exit 141, silent (script_driver.rs), matching child_process_exit_status's existing BrokenPipe arm for in-process children. - handle_external_file_builtins (external_file_builtins.rs): every emulated-external arm stands in for a forked disk child (execute_cmd.c:5522 execute_disk_command), so an EPIPE-class output error becomes exit_code 141 with no diagnostic — this is the exact path that produced the disclosed failure (`cat` replayed through write_cat_output into the dead coproc pipe). Verification (LF script files, both sides): - fail-first: 4/4 new pins red on base 0a405d8 with the disclosed `Broken pipe` diagnostic; all four green after the fix. - pins: tests/issue3475_coproc_child_broken_pipe_regressions.rs 4/4, issue3267 redirect-first pin file 22/22 (incl. the formerly racy F3 heredoc cell), issue1882/2893/440/1580/1822 neighbors all pass (#2102's one red cell reproduces identically on base). - GNU oracle: byte-for-byte match with WSL /usr/local/bin/bash 5.3.20 on the deterministic dead-pipe shapes (coproc builtin write, emulated cat write, heredoc-fed cat, group continuation) — no diagnostic, `wait` -> 0, rc 0. - lib: 1351 passed, failure set = {issue2084} = base. - fmt clean on touched files; RUSTFLAGS="-D warnings" cargo check --locked clean.
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.
Summary
Converts the Windows platform debt disclosed during the #3475 coproc rework into a real fix:
coproc <<HD catintermittently printedcase.sh: line 1: Broken pipewhen the parent exited or retired the coproc read end before the child's output write landed.Root cause: not the pipe lifetime. GNU models the coproc body as a fork — a forked child restores every signal's startup disposition (
execute_cmd.c:1670→trap.c:1480 reset_signal_handlers), so SIGPIPE is SIG_DFL and a write meeting a readerless pipe is the child's silent 141 death. rubash respawns fork-shaped bodies asrubash -cchildren (validatedRESPAWNED_CHILDprovenance), but the child's EPIPE still ran the main shell's write-failure path — the #440 report-and-continue model, which only applies to the main shell whose SIGPIPE stays SIG_IGN.Fix — two seams where a child's EPIPE verdict unwinds:
report_io_error_routed(ast_exec.rs): validated respawn child + EPIPE →ExecuteError::BrokenPipe(no diagnostic);-cdriver maps to 141 (script_driver.rs).handle_external_file_builtins(external_file_builtins.rs): emulated externals stand in forexecute_cmd.c:5522forked disk children — EPIPE-class output error → exit 141, silent. This is the exact path that produced the disclosed failure (cat→write_cat_output→ dead coproc pipe).Test plan
Broken pipediagnostic), green after fixtests/issue3475_coproc_child_broken_pipe_regressions.rs4/4 (deterministic: child sleeps past parent's read-end close)issue3267_coproc_redirect_first_regressions22/22 (incl. formerly racy F3 heredoc cell — 30/30 + 15/15 stress clean)issue1882/issue2893/issue440/issue1580/issue1822pass;issue2102single red cell reproduces identically on base (pre-existing)/usr/local/bin/bash5.3.20, LF script files — no diagnostic,wait→ 0, rc 0 on all dead-pipe shapescargo test --libWindows: 1351 passed, failure set{issue2084}= baseRUSTFLAGS="-D warnings" cargo check --lockedcleanGenerated with Devin