fix(previews): ffprobe hangs#60916
Open
adduxa wants to merge 1 commit into
Open
Conversation
Signed-off-by: Andrey Dyakov <adduxa@gmail.com>
solracsf
reviewed
Jun 2, 2026
| } | ||
| foreach ($read as $pipe) { | ||
| $chunk = fread($pipe, 8192); | ||
| if ($chunk === false) continue; |
solracsf
reviewed
Jun 2, 2026
| !feof($test_hdr_pipes[2]) ? $test_hdr_pipes[2] : null, | ||
| ]); | ||
| $write = $except = []; | ||
| if (stream_select($read, $write, $except, 5) === false) { |
Member
There was a problem hiding this comment.
This 5 is a per-iteration timeout. Only the false (error) return is handled; the 0 (timeout) return falls through, $read becomes empty, the foreach does nothing, and the while loops again. So if ffprobe truly hangs (produces no output and never closes its pipes), this spins every 5s forever: the same "hangs indefinitely" symptom the PR title targets, just via a different path.
Contributor
Author
There was a problem hiding this comment.
Thanks! I will search for the solution.
Do you know if stdout is always <64k here? Is it acceptable to just read stderr first in this case?
This approach is used at https://github.com/adduxa/server/blob/1bcc80b5f45a0d8619df64edbd2fec797fd70cd9/lib/private/Preview/Movie.php#L374 for ffmpeg
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
Fix pipe buffer deadlock in
useHdr()inlib/private/Preview/Movie.php.When
ffprobeproduces more than ~64KB on stderr, the sequentialstream_get_contentscallsdeadlock: PHP blocks reading stdout while ffprobe blocks flushing stderr. This caused
occ preview:generate-allto hang indefinitely on certain video files.A tempting workaround is to swap the two
stream_get_contentscalls (reading stderr first),but I'm not sure if ffprobe is guaranteed to produce <64KB on the stdout for this call.
Fix drains both pipes concurrently using
stream_selectwith non-blocking I/O.TODO
Checklist
3. to review, feature component)stable32)AI (if applicable)