Repository navigation
fix(tui): keep handling termination signals after stdin EOF - #1357
Merged
Merged
Conversation
A `future tui` whose terminal went away kept running with the SIGINT/SIGTERM/SIGHUP/SIGQUIT handlers installed and nobody draining the self-pipe they write to: the reader thread was the only reader of that pipe and it `break`s out of its loop at EOF, so a termination signal was captured and then silently dropped — its default action never ran either. `kill` returned 0, the process stayed, and only `SIGKILL` removed it (measured: six orphaned TUI processes that `pkill -TERM` could not touch). The reader no longer exits when stdin does. It sets `stdin_gone`, drops fd 0 from the poll set — a hung-up pty stays readable, so keeping it would spin — and keeps waiting on the signal pipe alone (`Backend::wait_for_signals`). The dispatch arms are unchanged, so resize, the app's exit callback and the restore-and-re-raise failsafe all keep working in that state, and `stop()` still joins the thread (it wakes the pipe). Cleanup cannot recreate "never exits" either: a caught termination signal arms an exit deadline (10 s, `FUTURE_TUI_EXIT_DEADLINE_MS` for tests) before the graceful callback runs. If it expires with the terminal still in raw mode, the existing failsafe restore runs and the process dies with the signal's default disposition. Nothing switches SIGTERM back to SIG_DFL as a shortcut. Tests: a unit test on a real PTY (signal still reaches the exit callback after the master closes) and six integration tests that spawn real processes (`tui/tests/signal_shutdown.rs`): SIGTERM/SIGINT/SIGHUP on a dead PTY exit within the timeout, a blocked cleanup is force-ended by the deadline, no-tty still exits on its own, and EOF alone still does not exit. Reverting the EOF arm makes four of them red. Record: docs/testing/tui-signal-shutdown-2026-10-26.md.
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.
What and why
A terminal UI must keep reacting to
SIGTERM/SIGINT/SIGHUPafter stdin reaches EOF. Before this change the terminal driver dropped its signal handling once stdin was exhausted, so a TUI whose terminal had gone away (closed SSH session, killed multiplexer pane) could linger instead of shutting down.The terminal driver now installs and keeps its signal handling independently of stdin lifetime, on both POSIX and Windows, and a blocked cleanup no longer prevents exit.
Commits
Verification
cargo fmt --all -- --check— cleancargo clippy -p future-tui --all-targets -- -D warnings— cleancargo test -p future-tui --lib— 1056 passedcargo test -p future-tui --test signal_shutdown— 6 passed (sigterm_stops_a_tui_whose_terminal_is_gone,sigint_and_sighup_stop_it_too,eof_alone_does_not_stop_the_process,a_blocked_cleanup_still_exits_on_sigterm,a_tui_with_no_tty_does_not_linger)make check-docs— 335 docs OK, provider matrix 13 rowsAll checks were run on this branch's tip with the pinned 1.97.0 toolchain.
Notes
The two
docs/testing/tui-signal-shutdown-2026-10-26*.mdfiles record the live verification of the scenarios above.