Fix/command read busy loop - #5259
Open
10ne1 wants to merge 2 commits into
Open
Conversation
fgets() returns nullptr on both a read error and at end-of-file and an
error sets ferror(), never feof().
The first failed read therefore spins the thread at 100% CPU for good,
because read() looped only on feof() and never returns.
(command::close() also never never reaps the child, nothing else does,
as the SIGCHLD handler only drains the list forkExec() fills).
Loop on fgets() which stops on both end-of-file and error, then check
ferror() so a failed read is not silently a truncated module output.
Reproduced by calling read() under a watchdog on a directory fd, whose
reads fail with EISDIR:
before: WATCHDOG: read() did not return after 3s -- SPINNING
after: [error] Error reading command output: Is a directory
read() RETURNED, 0 bytes
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
The regression this guards against does not fail a run, it wedges one, so the call goes in a child with a 5s watchdog and a return to the old behaviour is reported as a failure instead of a hang. Passes on the current code; with read() put back the way it was it fails with "command::read did not return within 5s". Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
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.
What does this PR do?
It fixes a busyloop at 100% cpu I noticed and adds a regresion test.
More details in the commit messages.
Related issues
No issue.
Checklist
clang-formatninja -C build)- [ ] Man page updated for any new/changed user-facing option (man/)