Repository navigation
fix(tui): exit when the terminal hangs up instead of spinning - #139
Merged
Merged
Conversation
crossterm's unix reader never returns once its tty hangs up (read gives Ok(0) forever, crossterm-rs/crossterm#793), so with SIGHUP ignored the app stayed behind at 100% CPU. A watch thread polls the terminal on stdin or stdout every 500 ms and exits with status 129 on POLLHUP. Refs #128
This was referenced Nov 14, 2026
Merged
1 task
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.
When the terminal closes and SIGHUP does not end the process (it is ignored, as under
nohup, or the launcher does not forward it), plannotator-tui stays behind as an orphan at about 100% CPU. crossterm's unix reader only leaves its read loop onWouldBlock. After a hang-up,readreturnsOk(0)forever, soevent::pollnever returns, whatever the timeout (crossterm-rs/crossterm#793, still open). The event loop never runs again.New
src/hangup.rs(unix only): right afterratatui::init, a thread polls the terminal every 500 ms and exits with status 129, the status SIGHUP would have left, whenpollreportsPOLLHUP.last --stdin) is skipped, because a pipe whose writer has finished also reportsPOLLHUP.poll, nottcgetattr/isatty. On macOS both keep succeeding on a pty whose controller has closed. I measured this before relying on it.ratatui::try_restore, notrestore.restoreprints its failure to stderr, which is the dead terminal too, and on my first try that print panicked inside ratatui's panic hook and aborted with status 134.rustixis already in the lock file through crossterm. It is a new direct dependency only on unix (event,stdio,termios;ptyfor tests).Checked on macOS in a private tmux server (
trap '' HUP, thentmux kill-server):last --stdinwith piped input, then hang-upA normal session (
qgives 0), SIGTERM (143), 3 s idle with piped stdin, and an$EDITORhandoff (o) all behave as before. The watch thread does not fire while the terminal is alive.Tests:
hangup::testsuses a real pty. It reads as hung up only after its controller is dropped, and a finished pipe on stdin is skipped in favour of the terminal.cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warnings,cargo test --workspace(297 in the app crate) pass. Windows: the module, its call and the dependency arecfg(unix).cargo clippy --target x86_64-pc-windows-msvc --workspace --all-targets -- -D warningspasses locally with a stub C compiler for the bundled sqlite. CI'scheck-windowsis the real build.Not fixed here, found while testing: on macOS,
last --stdinwith piped input already hangs on main at 99% CPU insidesupports_keyboard_enhancement, before the event loop. crossterm cannot register/dev/ttywith kqueue, so its query loops. That is a separate bug.Refs #128