Repository navigation
fix(playback): read FFmpeg log options under the session lock - #5128
Merged
Merged
Conversation
A restart starts the replacement FFmpeg before it publishes the new options under s.mu, and the new process's stderr logger read the log sink and session ID without that lock. Any FFmpeg that wrote stderr right after a restart raced the restart's write. Read them while holding s.mu, which both log helpers already take. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Contributor
4 tasks done
4 tasks done
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.
Problem
Related issue: N/A
Validation tasks: none
Other clients: N/A (no client-visible change)
A transcode restart races its own FFmpeg's stderr logger.
TranscodeSession.restartstarts the replacement FFmpeg and only then stores the new options ins.optsunders.mu. The new process's stderr copier callslogFFmpegLine, which reads.opts.FFmpegLogSinkwithout that lock. Any FFmpeg that writes to stderr right after a seek or recovery restart triggers it, andgo test -racereports a data race between the two. This change makes both FFmpeg log helpers read the session's options only while holdings.mu.Found in review of #4639.
Approach
logFFmpegLinealready tooks.mubefore writing to the sink. It now checks the sink after taking the lock instead of before.logFFmpegEventcopies the sink and session ID under the lock it already takes, then writes the event after unlocking, as before. Nothing else on the stderr path readss.optswithout the lock.Two other approaches were possible. Publishing the options before
cmd.Startwould also give the new process's first lines the new generation's attributes, but every Start-failure and closing path would then have to undo it. Having the stderr writer capture the sink when the process is set up would changeffmpegStderrWriter, which #4639 also edits. Reading under the existing lock is the smallest change that ends the race.Validation
Restartwith a fake FFmpeg that prints one stderr line. On the base it fails under-racewith the race betweenlogFFmpegLineandrestart; with the fix it passes 10 runs out of 10.go test -race ./internal/playback/...passes.make lint-changed: 0 issues.CI does not run
internal/playbackunder-race, so the new test catches a regression only in a-racerun.Evidence: https://evidence.siloserver.org/r/silo-server/transcode-restart-stderr-race/
Risks
A session without an FFmpeg log sink now takes
s.muonce per stderr line before it returns. The lock is uncontended in that case, and FFmpeg runs at-loglevel error, so stderr is low volume.Left as it was, because it predates this change:
logFFmpegLinestill calls the sink while it holdss.mu.restartpublishes its options still carry the previous generation's seek and start-segment attributes.Checklist
Council review
Ran as a follow-up of the #4639 review: one background reviewer at medium effort.
Rounds: 1, last reviewed 55f0ea3
No findings. The reviewer reproduced the race on the base at several GOMAXPROCS settings and saw the test pass on the head.
AI Disclosure
🤖 Generated with Claude Code
Note
Fix data race in FFmpeg log option reads in
TranscodeSessionFixes a race where a replacement FFmpeg process could emit stderr during a restart while the log sink was being read without the session lock.
TranscodeSession.logFFmpegLinenow reads the log sink unders.muand holds it through the logging-cap and line-write logic in transcode.goTranscodeSession.logFFmpegEventreads the sink, session ID, and event attributes unders.mu, then releases the lock before writing the eventlogFFmpegEvent, so writes may occur after the session state changesMacroscope summarized 55f0ea3.