Skip to content

Handle POLLNVAL in Terminal::wait_for_input - #41

Merged
azat merged 1 commit into
masterfrom
poll-fix
May 22, 2026
Merged

azat merged 1 commit into
masterfrom
poll-fix

Conversation

@azat

@azat azat commented May 22, 2026

Copy link
Copy Markdown
Member

poll reports POLLNVAL immediately when a watched fd has been closed or otherwise become invalid (for example, after a PTY teardown). The previous masks only covered POLLIN | POLLHUP | POLLERR, so neither branch fired and the while (true) loop spun at 100% CPU. Add POLLNVAL to the mask so the invalid fd is treated the same as a terminal/error condition - we read what we can from the interrupt pipe or surface a key-press event for the input fd, which lets the caller unwind cleanly.

`poll` reports `POLLNVAL` immediately when a watched fd has been closed
or otherwise become invalid (for example, after a PTY teardown). The
previous masks only covered `POLLIN | POLLHUP | POLLERR`, so neither
branch fired and the `while (true)` loop spun at 100% CPU. Add
`POLLNVAL` to the mask so the invalid fd is treated the same as a
terminal/error condition - we read what we can from the interrupt pipe
or surface a key-press event for the input fd, which lets the caller
unwind cleanly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@azat
azat merged commit 3a55a1b into master May 22, 2026
1 of 2 checks passed
@azat
azat deleted the poll-fix branch May 22, 2026 10:49
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