Skip to content

stream.ffmpegmux: ign pipe write err on stream end #6558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

bastimeyer
Copy link
Member

Don't log an error message when writing to the named pipe fails after the FFmpeg process has been terminated/killed.

Check if the substream has been closed or if the process does not exist anymore and then log the pipe-copy completion debug message.


Unfortunately, we don't have tests written for that. This is a race condition, depending on where the copy-to-pipe thread of each substream is currently at. If the next stream.read() call blocks and the result is an empty byte string due to the substream having been closed, then we log the completion message. But if some stream data has been read and it's being written to the named pipe while the FFmpeg process gets terminated/killed upon closing the stream, then we unintentionally log an error message. This needs to be fixed, because it's not an actual error.

Therefore just check if the substream has already been closed or if the FFmpeg process is not alive anymore.

Btw, this is just a band-aid fix, but it should be fine for now...

master

[18:16:45.590909][MainThread][stream.ffmpegmux][debug] Closing ffmpeg thread
[18:16:45.591167][ThreadPoolExecutor-0_0][stream.segmented][debug] Closing worker thread
[18:16:45.591420][ThreadPoolExecutor-0_0][stream.segmented][debug] Closing writer thread
[18:16:45.591547][ThreadPoolExecutor-0_1][stream.segmented][debug] Closing worker thread
[18:16:45.591631][DASHStreamWriter-video-0-executor_0][stream.dash][debug] video/mp4 segment 2924: cancelled
[18:16:45.591706][ThreadPoolExecutor-0_1][stream.segmented][debug] Closing writer thread
[18:16:45.591931][Thread-2 (copy_to_pipe)][stream.ffmpegmux][debug] Pipe copy complete: /tmp/streamlinkpipe-35426-2-9030
[18:16:45.592014][DASHStreamWriter-audio-0-executor_0][stream.dash][debug] audio/mp4 segment 2924: cancelled
[18:16:45.592623][Thread-1 (copy_to_pipe)][stream.ffmpegmux][error] Error while writing to pipe /tmp/streamlinkpipe-35426-1-6737: [Errno 32] Broken pipe
[18:16:46.030181][MainThread][stream.ffmpegmux][debug] Closed all the substreams
[18:16:46.030371][MainThread][cli][info] Stream ended

PR (reliably reproducible)

[18:17:49.745892][MainThread][stream.ffmpegmux][debug] Closing ffmpeg thread
[18:17:49.746155][ThreadPoolExecutor-0_0][stream.segmented][debug] Closing worker thread
[18:17:49.746242][ThreadPoolExecutor-0_0][stream.segmented][debug] Closing writer thread
[18:17:49.746411][DASHStreamWriter-video-0-executor_0][stream.dash][debug] video/mp4 segment 2956: cancelled
[18:17:49.746628][ThreadPoolExecutor-0_1][stream.segmented][debug] Closing worker thread
[18:17:49.746739][ThreadPoolExecutor-0_1][stream.segmented][debug] Closing writer thread
[18:17:49.747233][DASHStreamWriter-audio-0-executor_0][stream.dash][debug] audio/mp4 segment 2956: cancelled
[18:17:49.747391][Thread-2 (copy_to_pipe)][stream.ffmpegmux][debug] Pipe copy complete: /tmp/streamlinkpipe-35800-2-8857
[18:17:49.747602][Thread-1 (copy_to_pipe)][stream.ffmpegmux][debug] Pipe copy complete: /tmp/streamlinkpipe-35800-1-4402
[18:17:50.049528][MainThread][stream.ffmpegmux][debug] Closed all the substreams
[18:17:50.049756][MainThread][cli][info] Stream ended

Don't log an error message when writing to the named pipe fails
after the FFmpeg process has been terminated/killed.

Check if the substream has been closed or if the process does not exist
anymore and then log the pipe-copy completion debug message.
@bastimeyer bastimeyer merged commit 5e74ebe into streamlink:master Jun 12, 2025
17 checks passed
@bastimeyer bastimeyer deleted the stream/ffmpegmux/pipe-write-error branch June 12, 2025 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant