Repository navigation
WIP: fix(traps): #2482 fatal-unwind stack + ERR-in-pipeline (faces a/b); #2483/#2484 analysis - #2506
Conversation
eabd6cf to
3890916
Compare
… pipeline elements Refs #2482 Face a (bats cells 55/57/59/64): GNU execute_cmd.c:4506 calls run_debug_trap unconditionally for simple commands; the running_trap gate at execute_cmd.c:4498 covers only the the_printed_command_except_trap refresh. The #2212 F4 umbrella that silenced DEBUG inside the EXIT action was therefore wrong: the EXIT window now sets a dedicated exit_trap_running flag whose only job is the BASH_COMMAND freeze, and commands inside the action take their re-presentation firing with the frozen command. A fatal ExitCode/LastpipeExit unwind while `set -e` is live (flags.c:263 exit_immediately_on_error = errexit_flag) skips execute_function's frame pops (the uw_restore_funcarray_state unwind protect, execute_cmd.c:5329, run at :5418 only on the normal return), so the EXIT action executes with the dying call stack installed (eval.c:102-106). The function epilogue now leaks those frames — counted in ShellState's exit_unwind_leaked_frames — and the EXIT-trap funnel drops them after the action runs; FUNCNAME's att_invisible gates (variables.c:1812, cleared on the skipped epilogue path at execute_cmd.c:5167) honor the leak. The gate is the live -e flag at the failure point, not the suppression state: a DISCARD under a || suppression leaks every frame, while with -e off the DISCARD unwind runs the protects first (subst.c exp_jump_to_top_level -> sig.c:387 top_level_cleanup) and the EXIT trap sees a clean stack. Both directions are pinned. issue2212_13 is corrected to the re-presentation behavior. Face b (cell 133): a pipeline element is a subshell in GNU, so its ERR trap follows errtrace (trap.c:1480) exactly like a ( ) child — both pipeline stage builders now reset traps with reset_for_subshell_child instead of the unconditional variant. The element's own completion takes no wait-side adjudication (execute_pipeline has no wait frame for an element): the stage builder records the stage root's subshell_depth and execute_command's subshell tail skips the fire (and the paired debugger park) at exactly that depth; nested ( ) commands inside the body sit deeper and keep their wait-side fire. Regression pins (GNU bash 5.3.20 expectations, scrubbed runs): tests/issue2482_trap_unwind_stack.rs 8/8, tests/issue2482_err_trap_pipeline.rs 8/8, tests/issue2212_bats_remainder_regressions.rs stays 15/15. h-bats minis: t55/t57/t59/t64 green; the t133 pipeline face is fixed (the mini stays red on a pre-existing exit-in-EXIT-action ERR adjudication residual - see the cluster REPORT).
3890916 to
8d51e7f
Compare
…t133) GNU's run_error_trap call sites (execute_cmd.c:773/1000/1166/2909) only ever adjudicate a command that completed with a status; the exit builtin never returns one — builtins/exit.def exit_or_logout ends in jump_to_top_level (EXITBLTIN), and run_exit_trap (trap.c:1027) catches that jump with its own setjmp, so no frame the unwind crosses performs failure adjudication for an exit-terminated chain. execute_materialized_command's errexit tail fired maybe_run_error_trap whenever exit_code was nonzero under live errexit, including for an in-flight Err(ExitCode): once at the exit builtin's own dispatch frame (`set -eET; trap .. ERR; exit 1` fired in rubash, silent in GNU), and again at eval/source wrapper frames whose inner command had already been adjudicated (`eval 'false'` fired twice). In the bats cell-133 shape the extra fire re-ran bats_error_trap inside the EXIT teardown chain, printing a second raw "failure callback" line. Gate the tail's fire on result.is_ok() — the same rule the branch's conversion mark already applies (only an Ok completion is converted). In-flight unwinds propagate unchanged. Stacked on PR #2506 (fix/2482-2484-trap-stream), whose face-a/b trap machinery this adjudication sits in. Verification (GNU bash 5.3.20, script files): 33 probe shapes count-compared, core shapes byte-identical (exit chains in the body / EXIT action / eval / source / subshell / pipeline stage, plus ordinary-failure controls). New pins tests/issue2482_t133_err_retrigger.rs 16/16; #2506 pins 8/8 + 8/8; issue2212 15/15; adjacent trap/errexit targets all green. mini2212_t133.bats: ok, TAP identical to GNU (was not ok on the #2506 tip). Refs #2482
|
[win-acceptance] #2506 PASS on all pinned faces; one new divergence found on an unpinned shape, flagged (not self-fixed) — Windows-runnable pins all green x2 @--test-threads=4: NEW FINDING (A/B-verified, introduced by this family): with DEBUG + EXIT armed and a nounset DISCARD failure ( Environment: Windows 10 19045 real machine, MSVC Rust debug build of master 9348b8d (contains this merge), oracle |
…e unwind Refs unixwin#2546 (regression introduced by unixwin#2506) Root cause: unixwin#2506 taught the EXIT-trap window that commands inside the action take DEBUG re-presentation firings (correct for an ARMED trap: GNU execute_cmd.c:4506 calls run_debug_trap unconditionally for simple commands, and the running_trap gate at :4498 covers only the the_printed_command_except_trap refresh). But the funnel then consulted a trap table rubash had already re-armed: the function epilogue restored the entry-saved DEBUG action unconditionally, while GNU restores it via the uw_maybe_set_debug_trap unwind protect (execute_cmd.c:5276, registered next to uw_maybe_set_error_trap at :5286 and uw_maybe_set_return_trap at :5301) — and the fatal ExitCode/LastpipeExit unwind under live errexit longjmps past every one of those protects. The EXIT action therefore executes in the dying scope, where an untraced function had disarmed the DEBUG trap at entry (execute_cmd.c:5278 restore_default_signal), so run_debug_trap (trap.c:1275, `sigmodes[DEBUG_TRAP] & SIG_TRAPPED`) never fires — GNU prints no DEBUG record for the failing command. The frame-stack half of the same protect skip was already modeled (unixwin#2506's leaked frames, gated on exit_unwind); the trap-table half was missed, so master printed one extra `DEBUG cmd=[echo ${u2482bad}]`. Fix: hoist the epilogue's existing exit_unwind condition (Err(ExitCode | LastpipeExit) && errexit_enabled, the unixwin#2506 frame-leak gate) above the restores and skip the DEBUG/ERR/RETURN restores on that path — one invariant for the whole protect family, not a print-surface patch. With `-e` off the DISCARD unwind still runs the protects (sig.c:387 top_level_cleanup -> run_unwind_protects) and the restore rightly happens, so the action's first command keeps its re-presentation firing. Verification (WSL GNU bash 5.3.20 oracle, script files): - Both issue forms (p2482b function action, p2482c string action): stdout+stderr+exit byte-identical, extra DEBUG line gone. - Counting-law matrix 10/10 byte-identical: success/failure x function/top-level x DEBUG/EXIT/RETURN x functrace x -e off x nested x exit-builtin; the armed cells (top-level failure, functrace, -e off, success baseline) keep every re-presentation firing. - tests/issue2546_debug_overreport.rs 12/12; unixwin#2506 pins stay green (issue2482_trap_unwind_stack 8/8, issue2482_err_trap_pipeline 8/8, issue2212_bats_remainder_regressions 14/14); trap family (37 files) and cargo test --lib match pristine master exactly (the 6 trap-family and 2 lib failures reproduce on clean master).
Cluster C (trap timing + stream ordering family) — per-issue status:
Refs #2482 — face a FIXED; face b pipeline half FIXED, mini still red on a pre-existing residual (corrected 2026-11-02).
inside the EXIT action was wrong — GNU execute_cmd.c:4506 calls
run_debug_trap unconditionally; :4498 gates only the
BASH_COMMAND refresh. Removed the umbrella (dedicated
exit_trap_running flag for the freeze), and mirrored GNU's
fatal-unwind stack semantics: while
set -eis live at thefailure point (flags.c:263), an ExitCode unwind skips the frame
pops (execute_cmd.c:5329/5418), so the EXIT action sees the
dying stack; the epilogue leaks the frames and the EXIT-trap
funnel drops them after the action. With -e off, the DISCARD
unwind runs the protects (sig.c:387) and the stack is clean.
Minis t55/t57/t59/t64 green.
subshells — ERR now follows errtrace into elements
(reset_for_subshell_child at both stage builders), and the
element's own completion takes no wait-side adjudication
(stage-root depth marker; nested
( )commands keep theirs).All minimal pipeline shapes byte-identical to GNU; pins below.
the ERR trap a second time INSIDE the EXIT trap action, for the
action's command chain terminated by an inner
exit "$bats_exec_suite_status"— the fixture's on_failurecallback prints one extra raw line (6 vs GNU's 5). This is
PRE-EXISTING on the frozen tree (minimal probes: GNU 1 fire /
frozen 2; GNU 0 / frozen 1) and is the double-trigger the issue
text names for this cell; the exit unwind itself is clean. The
adjudication site is shared with the session/subshell exit
machinery and was not pinned to a safe gate tonight — see
REPORT.md face-b correction. An earlier "t133 green" note was
based on a contaminated delivery and is withdrawn.
identical to GNU); tonight's direct runs were polluted by VM
load ≈ 35 starving the disowned bg job — re-run on a quiet
machine before treating as a defect (REPORT.md).
8/8 (scrubbed, GNU 5.3.20 expectations, local artifacts);
issue2212 stays 15/15.
Refs #2483 — analysis only (in REPORT.md). Cells 115/116:
pipeline stage output is capture-then-emit, not streamed — a
producer's bytes sit in the stage machinery until the stage
completes, so a later direct stderr write from the suite process
overtakes the TAP stream (minimal repro in REPORT). This is the
#2244 drain-model family; the fix is the write-through streaming
rework, not safe on release night.
Refs #2484 — analysis only (in REPORT.md). Cell 118: inside a
pipeline-stage function,
exec 3<&1binds fd 3 to the stage'sstdout-capture (drained to the output file) instead of the
inter-stage pipe, so
bats_tee's>(cat >&3)copy lands in thefile twice and the next stage gets nothing (fd-3 repro in
REPORT); the procsub delivery-timing half is the same drain
family as #2483.
Full report: cluster workdir REPORT.md
(~/workspace/rubash-wave-20261102/c-traps/REPORT.md). One commit
for #2482 (amended once to correct the mini tally); no code
change for #2483/#2484 by design of the split delivery.