fix(cli): suppress OSError EIO on interrupt shutdown (salvages #13720, closes #13710)#15834
Merged
Conversation
When the user interrupts a long-running task, prompt_toolkit tries to
flush stdout during emergency shutdown. If stdout is in a broken state
(redirected to /dev/null, pipe closed, terminal gone), the flush raises
`OSError: [Errno 5] Input/output error` which propagates unhandled and
crashes the CLI.
Two defense layers:
1. `_suppress_closed_loop_errors`: add `OSError` with `errno.EIO` to
the asyncio exception handler, matching the existing pattern for
`RuntimeError("Event loop is closed")` and `KeyError("is not
registered")`.
2. Outer `except (KeyError, OSError)` block: add `errno.EIO` check
before the existing string-match guards, silently suppressing the
error instead of printing a misleading stdin-related message.
Fixes #13710.
Collaborator
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.
Salvages @voidborne-d's PR #13720 onto current main.
Summary
Interrupts during long-running tasks crashed with
OSError: [Errno 5] Input/output errorwhen prompt_toolkit's vt100 renderer flushed a broken stdout during emergency shutdown._suppress_closed_loop_errorsonly caughtRuntimeError+KeyError, and the outerexcept (KeyError, OSError)only matched "Bad file descriptor" — EIO fell through and killed the process.Changes
cli.py: EIO guard added to both the asyncio exception handler and the outer stdin-unusable except block. Silently suppressed (correct — this only fires during interrupt teardown).tests/hermes_cli/test_suppress_eio_on_interrupt.py: new, 9 tests covering EIO suppression + non-suppression of unrelated errors.scripts/release.py: AUTHOR_MAP entry for voidborne-d's personal commit email.Validation
Closes #13710. Credits #13720 (@voidborne-d). #13792 is a narrower attempt at the same issue and will be closed in favor of this.