Repository navigation
WIP: fix mid-wait untrapped Ctrl+C killing interactive sessions (niubash#698) - #2145
Merged
Merged
Conversation
…RD in interactive sessions (niubash#698) observe_signals_while_blocked — the mailbox drain every blocked wait polls on Windows (wait_external_child, the #2020 pipeline member waits, the non-unix builtin sleep) — converted an untrapped delivery to a bare ExitCode(128+sig) without the discard classification its two sibling drains attach (the boundary dispatch in run_pending_signal_traps; the wait builtin's drain, rubash#1825). The source driver therefore recorded an exit jump, Session::run reported Flow::ExitRequested(130), and niu's REPL ended the whole process at rc=130 on an untrapped Ctrl+C during a foreground command — where GNU jobs.c:3064 wait_for observes the recorded ^C and jobs.c:3315 ADDINTERRUPT throws to the top-level reader (DISCARD): the job settles 130 and the session survives. Mirror the sibling classification at the drain (interactive = the executor's session flag, as at both sibling sites; non-interactive sessions set nothing and keep the exit classification byte-identically), and keep the mark's invariant — a mark classifies the unwind it was set for and never outlives its unit — at the two places that convert or swallow that unwind: the unix sleep fold that forgets a shell-only SIGINT consumes the mark with the delivery, and run_source_impl's SigintUnwind arm consumes a mark the same interrupt left behind. Pins: tests/issue698_untrapped_sigint_midwait_discard.rs — Windows Session faces (builtin sleep / external / non-interactive guard) where the mailbox wait lives, unix PTY + die-by-signal guards, and the mid-sleep fold bookkeeping pair. Refs unixwin/niubash#698
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.
Refs unixwin/niubash#698 (closure comes after niu-side verification of the merged engine; this PR does not close it)
Defect (confirmed by the issue's native-harness re-verification)
In interactive niu on Windows, an untrapped Ctrl+C during a foreground command (
sleep 10) exited the whole shell with rc=130 in ~101ms — no prompt return. niu'swatch_imp::deliver(ctrl_c.rs:395) interrupts the foreground command through the engine mailbox (inject_console_ctrl_c+ group broadcast); the delivery chain itself is sound (trapped face GNU-aligned, chord verifiably consumed). The failure is the classification of what the engine's mid-wait drain does with the delivery.Localization
The engine has three mailbox drains that convert an untrapped delivery into
ExecuteError::ExitCode(128+sig):signal_discard_pending) for interactive sessions?run_pending_signal_trapswaitbuiltin'swait_pending_signal_status(rubash#1825)observe_signals_while_blocked(mid-wait)observe_signals_while_blockedis the only consumer on the paths where no kernel delivery adjudicates first: the Windows foreground external wait, the #2020 pipeline member waits, and the non-unix builtinsleep. Its bareExitCode(130)reachesrun_source_impl, which — finding no discard mark — records an exit jump;Session::runthen reportsFlow::ExitRequested(130), and niu's REPL (which correctly honors the mark when set, niubash#610note_exit_code_unwind) ends the process.Face-split probes (Linux, this tree vs GNU bash 5.3.20 oracle): standalone
rubash -iunder a PTY — ^C duringsleep 10re-prompts with$?=130, identical to GNU (the unix kernel path uses the foreground-wait SIGINT guard +fg_sigint_unwind, never this drain). Non-interactive-c+ group SIGINT: both shells die by SIGINT immediately — the shape this PR preserves byte-identically. Verdict: the defect is the mailbox-delivery classification only; it is niu-visible because niu's console Ctrl+C is an event-shaped mailbox delivery on Windows.Fix (by mechanism)
GNU: jobs.c:3064
wait_forobserves the recorded ^C during the wait; jobs.c:3315 ADDINTERRUPT throws the interrupted wait to the top-level reader as a DISCARD — the job settles 128+SIGINT and the interactive session survives; a non-interactive shell keeps the exit classification.observe_signals_while_blocked's untrapped branch now makes the same classification as its two sibling drains: recordexit_code = 128+sigand, when the session is interactive, setsignal_discard_pending. Interactivity is read from the executor's session flag — the host-declared session state both sibling sites read — never from the process environment. Non-interactive sessions set nothing.exitin the same unit would be misclassified as a discard), andrun_source_impl'sSigintUnwindarm consumes a mark the same interrupt left behind before the wait converted it to that spelling.Trapped deliveries (re-queue semantics), the §6.4 stale-discard ruling, and #2020's tree-kill settle behavior are untouched.
Pins —
tests/issue698_untrapped_sigint_midwait_discard.rsinject_signalduring (a) builtinsleep 30and (b) externalping -n 30: run settles fast at 130 withFlow::Completedand the session continues; (c) non-interactive guard: same injection keepsFlow::ExitRequested(130).sleep^C guard (NEXT_130, session alive); non-interactive group-SIGINT dies-by-signal guard; the mid-sleep fold bookkeeping pair (a forgotten queued SIGINT leaves no mark — a followingexit 3still exits; and completes normally at 0).Local verification: unix pins 4/4 green; the settlement unit was additionally proven with a temporary in-crate probe (removed before commit): baseline fails exactly at "discard mark must be set" for the interactive arm while producing the same ExitCode(130); the fold pin goes red if the fold's mark consumption is reverted. Regression battery green: lib 965/1 (the 1 is the known perennial
ownership_unary_operators_check_existing_file), #1639/#1662/#1825/#1990-1991/session-api-interrupt/signal-trap suites all pass; #2020's file is windows-gated (compiles, 0 local tests).niu-side assessment
No niubash change is needed. niu already consumes this exact classification on every route:
Shell::note_exit_code_unwind(niubash#610) checkstake_signal_discard_pending()for eachExecuteError::ExitCodeunwind out ofexecute_ast, and repl.rs ends the session only whentake_session_exit_jump()was armed — a discard never arms it. The Session route classifies through the samerun_source_impl. With the mark now set on the mid-wait path, niu's REPL will simply regain control with$?=130. Thedeliverpath itself (#669) needs no change. (A companion cluster is editing niubash-runtime shell.rs startup regions; this fix touches no niu code and no startup region.)