Repository navigation
fix(executor): broken-pipe writes no longer abort the interpreter (rubash#440) - #455
Merged
Merged
Conversation
caomengxuan666
added a commit
that referenced
this pull request
Oct 10, 2026
…#478) - Delete docs/{TASK-BOARD,TASKBOARD,QUEUE-PROMPTS,PERF-BASELINE,CORPUS-COVERAGE,COMPATIBILITY-STATUS,LINUX-RUN-STATUS}.md: dated status snapshots / session handoffs whose content lives in git history and the issue tracker. Still-valid baseline numbers (perf table, corpus coverage, 2026-10-02 compat ledger) are excerpted into issue #477. - AGENTS.md/README/README.zh-CN: repoint dangling references to the issue tracker. - CHANGELOG: record SIGPIPE semantics (#455), interactive input C0 normalization (#458), and android bionic targets (#456) under Unreleased. Co-authored-by: docs-audit <[email protected]>
caomengxuan666
added a commit
that referenced
this pull request
Oct 10, 2026
…osing command runs (rubash#485) (#494) * fix(executor): comsub reap publishes its status to $? before the enclosing command runs (rubash#485) GNU command_substitute (subst.c:7143) reaps the substitution child in the parent and the child's exit status becomes last_command_exit_value at that moment - BEFORE the enclosing command runs - so every later expansion on the same command line sees it, and a SUCCESSFUL substitution clobbers the previous status just the same. Probes, WSL GNU bash 5.3.0 (/usr/local/bin/bash, 2026-10-10): echo "$(cd nope && pwd)" $? -> " 1" (rubash: " 0" - the issue repro) echo "$(exit 3)" $? -> " 3" false; echo "$(true) $?" -> " 0" (unconditional reap contract) true; echo $? "$(exit 3)" -> "0 " (left-to-right: $? BEFORE keeps old) echo "$(exit 3)$?" -> "3" (same-word trailing fragment) echo a`exit 3`b $? -> "ab 3" (embedded backtick word) v="$(exit 3)$?" -> v=3, rc=3 (assignment keeps last comsub) false; x=$(true) y=$? -> y=0, rc=0 f(){ local v="$(exit 3)$?"; } -> v=3, rc=0 (declaration builtin masks) rubash recorded the substitution's status only in the last_command_substitution_status cell and promoted it at the two consumption sites (vanished-words null command, assignment RHS tail), so the word-expansion path never published it: every mid-line $? read the stale pre-expansion value. Fix - publish the reaped status at each parent-side completion point: - embedded_mutations.rs run_ast_command_substitution_with_context and run_function_command_substitution tails: exit_code = status at the fork boundary instead of restoring the pre-comsub value (the in-place executor IS the parent side of GNU's waitpid; saved_exit_code dropped exactly the status GNU publishes) - embedded_mutations.rs expand_command_substitution_mut_typed_with_context: the three fallbacks that run through the &self expand_command_substitution_with_context wrapper (specialized cd/pwd path incl. the #484 fast path, specialized builtins, final fallback) promote the wrapper's status cell - the wrapper is &self and cannot write the field - command_prepare.rs whole-word quoted "$(...)" fast path: same promotion after the wrapper call - parameter_core.rs expand_word_mut_with_context: embedded-backtick words route to the mutable embedded walker (the production path for every $( )-bearing word) instead of the legacy &self expand_word fallback, whose completions cannot publish status Unchanged on purpose (GNU-verified): the enclosing command's own status still overwrites when it runs (echo $(false); $? = 0); set -e aborts on a failed comsub assignment with its rc (D case, 1 / 4) and does NOT abort on a word-attached comsub failure; local/declare mask the assignment status (rc 0); nested comsub reports the outer body's own last status to the parent. Known adjacent gap, NOT touched (pre-existing, separate subsystem): in a pipeline, stage words are expanded in a pre-pass, so `true; echo $? "$(exit 3)" | tr -d ' '` prints 3 where GNU prints 0 - the later word's comsub runs before the earlier word's $? expands. The pre-pass predates this fix (which only made its status observable); filing separately. Also pre-existing: the cd/pwd comsub fast path stays silent on stderr where GNU prints the cd diagnostic (status and stdout match). Verification: tests/issue485_comsub_status_propagation.rs 13/13 (oracle probes above baked as assertions; set -e D case included). Adjacent suites green: issue70, issue343_345, issue440 (#455 lane), issue71, issue154, issue305, issue319, issue335, issue354, issue362, issue368, issue376, issue379, issue384, issue416_417, posixexp2, comsub_nonascii, conformance runner 22/23 (03-cond-unclosed-bracket pre-existing, GNU aborts the same shape with rc 2). Full cargo test --no-fail-fast: failure set byte-identical to the pre-fix tree (68 host-env failures compared name-by-name with the three fixed files reverted: pwd/path drive rendering, tilde-user fixture, bashdb fixtures, prompt/cli env classes; empty both-way diff); lib 636 passed / 2 failed = the master host-env pair. Closes #485 * fix(executor): cd/pwd comsub shortcut prints the #491 diagnostic once, not per admission probe The #491 merge added the cd diagnostic to command_substitution_cd_pwd_output - but the mut_typed word path consults that helper TWICE: first as the admission probe (command_substitution_uses_specialized_path calls it with .is_some() to admit the specialized path), then for the real expansion inside the &self wrapper's inner walk. Each failure printed the diagnostic, so `x="$(cd nope && pwd)"` and `local y="$(cd nope && pwd)"` reported `cd: nope: No such file or directory` twice where GNU bash 5.3.0 prints it once (probe vs script-file oracle, /usr/local/bin/bash, byte-compare on both shapes). Split the helper: the single-arg form (real expansion) keeps the emission; the probe goes through command_substitution_cd_pwd_output_quiet_probe, which suppresses only the diagnostic - status cell, output, and admission result are unchanged. Verification: both #485 suites green (tests/issue485_comsub_status_ propagation.rs 13/13, tests/issue485_comsub_status_word_propagation.rs 13/13); 17-form oracle matrix byte-identical to GNU 5.3.0 including the cd shapes now that the diagnostic prints once; full cargo test --no-fail-fast failure set identical to the pre-merge baseline (68 host-env failures, empty both-way diff).
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.
Issue
Fixes #440 — a SIGPIPE/broken-pipe in a pipeline's upstream stages made the whole interpreter (niu) exit 141 and abandon the remaining script commands.
Root cause
GNU bash's parent shell keeps SIGPIPE at SIG_IGN — only forked external commands die of it. A builtin (or in-process subshell) whose write hits a closed pipe gets EPIPE, reports the failed write with status 1, and the script keeps running.
In rubash, on Windows the same failure surfaces as ERROR_BROKEN_PIPE (109) / ERROR_NO_DATA (232). The executor's command-list error arms in
src/executor/ast_exec.rsmatched closed-output IoErrors withis_closed_output_io_errorand returned them as fatalExecuteError::IoErrorpast the list boundary;external_finish::child_process_exit_statusdid the same for in-process child scripts ("fatal to the whole process"). Result: after the first broken-pipe write the driver printedrubash: Broken pipeand stopped reading the script — the exact "niu rc=141, subsequent commands never execute" shape of #440.Fix
Treat a closed output as the hitting command's own write failure, mirroring bash's builtin
write error: Broken pipehandling:src/executor/ast_exec.rs: drop the 7is_closed_output_io_errorfatal-propagation arms; closed-output IoErrors now flow through the ordinary command-owned IoError handling — diagnostic to stderr, command status 1, list continues, errexit still promotes it to a clean exit 1.src/executor/external_finish.rs: a subshell's broken shared stdout is the child's status 1 (reported), not a process-fatal error.The pipeline machinery's own SIGPIPE semantics are untouched: the lingerer 141 shape from #382 (
lingerer_sigpipe_status), silenced broken-pipe stage payloads inpipeline_stages.rs, andset -o pipefailpropagation all still apply — only the interpreter no longer dies or aborts.Verification (target/debug/rubash.exe, Windows)
rubash -c 'yes | head -c 1 >/dev/null; echo rc=$?'→rc=0, shell exits 0cat <large file> | head -c 1, and a 200k-line builtin-producer loop intohead -c 1) →rc=0set -o pipefail; yes | head -c 1 >/dev/null; echo rc=$?→rc=141(last-stage/PIPESTATUS SIGPIPE shape preserved) and the shell continues to the next commandrubash: Broken pipe; now reports the write error, runs all remaining commands, exits with the last command's statusTests
New black-box suite
tests/issue440_broken_pipe_shell_survival.rs(spawnsCARGO_BIN_EXE_rubash, closes the child's stdout pipe after the first line, all runs deadline-bounded):broken_stdout_does_not_abort_the_script— remaining commands run,Broken pipediagnostic present, clean exitbroken_stdout_in_subshell_keeps_parent_runningerrexit_promotes_broken_write_to_status_one— exit 1, not 141/abortSuites run with no new failures vs. the clean tree:
issue382_hardkilled_lingerer_sigpipe_status,issue158_pipeline_drain_deadlock,issue144_merged_stream_order,issue429/issue330/issue385pipeline regressions,executor_tests(1587 tests),cli_tests(473),regression— the handful of failing tests in the latter groups fail identically on the unmodified tree (missingthird_party/bashsubmodule / missing externals on PATH / timing-sensitive canary), verified by stash-baseline runs.cargo fmtapplied (rustfmt pre-commit hook passed).