Skip to content

Fix/command read busy loop - #5259

Open
10ne1 wants to merge 2 commits into
Alexays:masterfrom
10ne1:fix/command-read-busy-loop
Open

Fix/command read busy loop#5259
10ne1 wants to merge 2 commits into
Alexays:masterfrom
10ne1:fix/command-read-busy-loop

Conversation

@10ne1

@10ne1 10ne1 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

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

  • Code is formatted with clang-format
  • Builds locally (ninja -C build)
    - [ ] Man page updated for any new/changed user-facing option (man/)
  • Tested against the affected module(s)

10ne1 and others added 2 commits August 19, 2026 18:15
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>
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