Repository navigation
fix(api): guard stdio redirect when stdin is missing (closed fd 0) - #4815
Closed
HoneyTyagii wants to merge 1 commit into
Closed
HoneyTyagii wants to merge 1 commit into
HoneyTyagii wants to merge 1 commit into
Conversation
Collaborator
|
Thanks for this! Closing as superseded: #4464 already fixed #4580 at the source — both spawners ( |
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.
Summary
hindsight_api/daemon.py:_redirect_stdio_to_log()so a daemon child started with fd 0 closed no longer crashes.sys.stdinto None, and the old unguardedsys.stdin.fileno()raisedAttributeError: 'NoneType' object has no attribute 'fileno'.stdinto DEVNULL after fix(embed): pin stdin to DEVNULL when spawning the daemon #4464, but the child redirect path still assumed a valid stdin, so direct launches and any other spawner without DEVNULL still hit the traceback from hindsight-embed: POSIX daemon spawn omits stdin=DEVNULL — child of a closed-fd0 parent dies in _redirect_stdio_to_log() (AttributeError: 'NoneType' object has no attribute 'fileno') #4580.Root cause
Old code did:
If
sys.stdinis None, thefileno()call crashes before the daemon can redirect stdio, leaving the "Failed to start daemon" 180s stall described in the issue.Fix
sys.stdinis None or itsfileno()raises.dup2in the same None and OSError guards, so a closed or missing output stream cannot crash the redirect either.Verification
python -m py_compile hindsight-api-slim/hindsight_api/daemon.pypasses.ruff check hindsight-api-slim/hindsight_api/daemon.pypasses.sys.stdin=None:_redirect_stdio_to_log()completes without error and only redirects stdout and stderr (2 dup2 calls). Same for a stdin whosefileno()raises ValueError.hindsight-api-slim/tests/test_daemonize.pycovers parent and child paths; full pytest run was not possible here because the sandbox lacks a C toolchain for optional native deps, but the touched function has no signature change.Fixes #4580