Skip to content

fix: do not hang using all of a core when the terminal is closed while prompting - #1481

Merged
dsherret merged 2 commits into
mainfrom
fix/prompt-terminal-closed
Nov 29, 2026
Merged

dsherret merged 2 commits into
mainfrom
fix/prompt-terminal-closed

Conversation

@dsherret

Copy link
Copy Markdown
Member

On Unix, an interactive prompt (ex. dprint init) kept running forever using all of a core when its terminal was closed and the process wasn't ended by SIGHUP, such as when it's ignored or it's not the process' controlling terminal.

Crossterm's read ignores the end of the input and errors reading it, so it never returns and can't be interrupted. A key is now read on another thread while waiting for either the key or the terminal to be closed, where the latter makes the prompt fail with "The terminal was closed." The read is abandoned in that case, and the process exits after the error.

Windows reads keys as before.

Tested manually on Linux by closing a pty while dprint init was prompting: without a controlling terminal, with SIGHUP ignored, and with stdin not being a terminal (so keys are read from /dev/tty). Also adds unit tests that use a pty. Not manually tested on macOS, where a /dev/tty that can't be polled isn't watched and so behaves as before.

@dsherret
dsherret merged commit b2b6496 into main Nov 29, 2026
6 checks passed
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