Skip to content

fix(tui): keep handling termination signals after stdin EOF - #1357

Merged
huichen merged 1 commit into
mainfrom
pr/huichen
Oct 25, 2026
Merged

huichen merged 1 commit into
mainfrom
pr/huichen

Conversation

@huichen

@huichen huichen commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

What and why

A terminal UI must keep reacting to SIGTERM/SIGINT/SIGHUP after 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

  • fix(tui): keep handling termination signals after stdin EOF

Verification

  • cargo fmt --all -- --check — clean
  • cargo clippy -p future-tui --all-targets -- -D warnings — clean
  • cargo test -p future-tui --lib — 1056 passed
  • cargo 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 rows

All 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*.md files record the live verification of the scenarios above.

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.
@huichen
huichen enabled auto-merge (squash) October 25, 2026 18:18
@huichen
huichen merged commit c722648 into main Oct 25, 2026
10 checks passed
@huichen
huichen deleted the pr/huichen branch October 25, 2026 18:30
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