Skip to content

fix(executor): respawned fork-children die silently on EPIPE like GNU SIGPIPE (Refs #3475) - #3753

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/3475-respawn-child-sigpipe
Nov 16, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/3475-respawn-child-sigpipe

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Converts the Windows platform debt disclosed during the #3475 coproc rework into a real fix: coproc <<HD cat intermittently printed case.sh: line 1: Broken pipe when 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 as rubash -c children (validated RESPAWNED_CHILD provenance), 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); -c driver maps to 141 (script_driver.rs).
  • handle_external_file_builtins (external_file_builtins.rs): emulated externals stand in for execute_cmd.c:5522 forked 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

  • fail-first: 4/4 new pins red on base (Broken pipe diagnostic), green after fix
  • new pin file tests/issue3475_coproc_child_broken_pipe_regressions.rs 4/4 (deterministic: child sleeps past parent's read-end close)
  • issue3267_coproc_redirect_first_regressions 22/22 (incl. formerly racy F3 heredoc cell — 30/30 + 15/15 stress clean)
  • neighbors issue1882/issue2893/issue440/issue1580/issue1822 pass; issue2102 single red cell reproduces identically on base (pre-existing)
  • GNU oracle byte-for-byte: WSL /usr/local/bin/bash 5.3.20, LF script files — no diagnostic, wait → 0, rc 0 on all dead-pipe shapes
  • cargo test --lib Windows: 1351 passed, failure set {issue2084} = base
  • fmt clean; RUSTFLAGS="-D warnings" cargo check --locked clean
  • Linux lib leg: deferred to CI (no local cargo toolchain in WSL)

Generated with Devin

… 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.
@caomengxuan666
caomengxuan666 merged commit 8100d76 into master Nov 16, 2026
7 of 11 checks passed
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.

1 participant