Skip to content

fix(playback): read FFmpeg log options under the session lock - #5128

Merged
Quick104 merged 1 commit into
mainfrom
fix/transcode-restart-stderr-race
Nov 22, 2026
Merged

Quick104 merged 1 commit into
mainfrom
fix/transcode-restart-stderr-race

Conversation

@Quick104

@Quick104 Quick104 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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.restart starts the replacement FFmpeg and only then stores the new options in s.opts under s.mu. The new process's stderr copier calls logFFmpegLine, which read s.opts.FFmpegLogSink without that lock. Any FFmpeg that writes to stderr right after a seek or recovery restart triggers it, and go test -race reports a data race between the two. This change makes both FFmpeg log helpers read the session's options only while holding s.mu.

Found in review of #4639.

Approach

logFFmpegLine already took s.mu before writing to the sink. It now checks the sink after taking the lock instead of before. logFFmpegEvent copies 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 reads s.opts without the lock.

Two other approaches were possible. Publishing the options before cmd.Start would 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 change ffmpegStderrWriter, which #4639 also edits. Reading under the existing lock is the smallest change that ends the race.

Validation

  • New test drives Restart with a fake FFmpeg that prints one stderr line. On the base it fails under -race with the race between logFFmpegLine and restart; 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/playback under -race, so the new test catches a regression only in a -race run.

Evidence: https://evidence.siloserver.org/r/silo-server/transcode-restart-stderr-race/

Risks

A session without an FFmpeg log sink now takes s.mu once 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:

  • logFFmpegLine still calls the sink while it holds s.mu.
  • Stderr lines that the replacement process writes before restart publishes its options still carry the previous generation's seek and start-segment attributes.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or how I checked a change nobody sees.

Council review

Ran as a follow-up of the #4639 review: one background reviewer at medium effort.

Rounds: 1, last reviewed 55f0ea3

Member Round 1
Sol (gpt-6.2-sol, medium) 9/10

No findings. The reviewer reproduced the race on the base at several GOMAXPROCS settings and saw the test pass on the head.

AI Disclosure

  • Harness: Claude Code in T3 Code
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5 (implementation, code-review); claude-sonnet-5-5 (code-review cleanup finder and validation check); gpt-6.2-sol (background review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: multi-agent code-review at medium effort found no defects in this change and raised the two pre-existing items under Risks. The plan round was skipped because the fix is mechanical. See Council review for the background review.

🤖 Generated with Claude Code

Note

Fix data race in FFmpeg log option reads in TranscodeSession

Fixes 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.logFFmpegLine now reads the log sink under s.mu and holds it through the logging-cap and line-write logic in transcode.go
  • TranscodeSession.logFFmpegEvent reads the sink, session ID, and event attributes under s.mu, then releases the lock before writing the event
  • Adds a regression test in restart_locked_test.go that restarts with a replacement process emitting stderr immediately and waits up to 10 seconds for the line to reach the sink
  • Behavioral Change: log sinks and event writes now happen after mutex release in logFFmpegEvent, so writes may occur after the session state changes

Macroscope summarized 55f0ea3.

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]>
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 22, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T18:30:35.282014Z 55f0ea3 PR opened
🔒 Security Review ✅ Completed 2026-11-22T18:32:48.311706Z 55f0ea3 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

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

silo-kody Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

FFmpeg line and event logging now read the configured sink under the session mutex. A restart test checks that a replacement process’s stderr line reaches the configured log sink.

Changes: FFmpeg logging

Layer / File(s) Summary
Synchronized sink access and restart coverage
internal/playback/transcode.go, internal/playback/restart_locked_test.go
Line and event logging snapshot the sink under the session mutex and write only when it is set. The restart test checks delivery of a replacement process’s stderr line to the configured sink.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested labels: bug, go, impact: playback

Suggested reviewers: blurbery, rangodj

Merge Risk: Minimal · up to 55f0e

This change fixes a data race between FFmpeg restart and stderr logging by reading the log sink under the session lock, and it adds a restart test. No merge-blocking risk was found. The only cost is an extra lock acquisition per stderr line.

Security architecture risk: Minimal · up to 55f0e

This change synchronizes access to logging options without expanding external access or process authority. No introduced or worsened architecture-level risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: FFmpeg log options are now read under the session lock, which is the fix for the data race between restart and the stderr logger. It follows the conventional-commit st…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description is specific and on-topic. It explains the data race between TranscodeSession.restart and the stderr logger, names the affected helpers (logFFmpegLine and logFFmpegEvent), and describes…
Full details: Title check

Explanation

The title names the main change: FFmpeg log options are now read under the session lock, which is the fix for the data race between restart and the stderr logger. It follows the conventional-commit style and is specific enough for a reviewer scanning history.

Full details: Description check

Explanation

The description is specific and on-topic. It explains the data race between TranscodeSession.restart and the stderr logger, names the affected helpers (logFFmpegLine and logFFmpegEvent), and describes the fix of reading FFmpegLogSink and the session ID under s.mu. It also covers the regression test, validation runs, and tradeoffs, which match the raw summary of changes in internal/playback.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c910ce1b-fecb-415c-844e-180b5b7592b4
Commits

Reviewing files that changed from the base of the PR and between f26cb9f and 55f0ea3.

Files selected for processing: 2

  • internal/playback/restart_locked_test.go
  • internal/playback/transcode.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish triaged High-confidence review completed; does not mean fixed, validated, or accepted for release. labels Nov 22, 2026
@coderabbitai coderabbitai Bot added the impact: playback Can't play, stalls, or wrong media label Nov 22, 2026
@Quick104
Quick104 merged commit 4d5040e into main Nov 22, 2026
18 checks passed
@Quick104
Quick104 deleted the fix/transcode-restart-stderr-race branch November 22, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority. triaged High-confidence review completed; does not mean fixed, validated, or accepted for release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant