Repository navigation
fix(playback): demux a whole subtitle track when the file's random reads are slow - #4302
Conversation
…ads are slow A whole read of an embedded subtitle track through the file's index makes one random read per cue. On storage that fetches a large chunk for each small read, such as a mount of remote storage with a local read cache, that takes minutes and starves any playback stream reading the same file. The read now gives way once its last 16 reads averaged over 500 ms: it sends no more reads and returns ErrSlowReads, and the request demuxes the source, which reads the file in order. Reads already sent finish, so a track they complete is still read. A track only the index can read has no demux to give way to and is read as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 12 minutes. View limit details
|
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:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
Security findingsAdvisory findings (1)ℹ️ 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. |
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: 5f73e2d990
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
…emux A PGS window open to the end reads the track whole. When that read gives way to slow reads, the warm it starts went through the index again, paying the slow first round once more before it demuxed. Treat ErrSlowReads like a slow window read and warm with the demux directly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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:
|
Problem
Related issue: N/A
Validation tasks: none
Other clients: Apple N/A, Android N/A, Roku N/A (server-side fix; clients get it without a change)
On storage where every random read is slow and pulls a large chunk, such as a FUSE mount of remote storage with a local read cache, reading a whole embedded subtitle track through the file's index takes minutes. Those reads also starve the playback stream reading the same file. A client asking for a whole PGS track during direct play got nothing in 150 seconds of retries, and the video stalled. This change makes that read give way after its first round of reads, and the request demuxes the file in order instead. #4272 fixed the same problem for subtitle windows. This fixes it for whole tracks.
A whole-track read makes one random read per cue, 16 at a time. It runs for up to 3 minutes, keeps going after the request stops waiting at 90 seconds, and is the only way a node reads a whole track before it is kept. These callers start it: sidecar requests without a position (including offline-download sidecars), windows open to the end, jellycompat track requests and its PlaybackInfo text warm, AI translation, and the subtitle prefetch.
Approach
embeddedsub.ReadOptionsgainsSlowRead. The reader times each read; once the last 16 averaged more thanSlowRead, reads that start afterwards fail withErrSlowReads. Reads already sent finish, so a track whose reads all went out in the first round still comes back whole.Store.Windowreads from the source after a kept copy fails. The time includes waiting behind the read's own 16 requests. Network storage answers in tens of milliseconds, and a disk that serves reads one at a time in up to a few hundred. The simulated mount in the runs below averaged 780 ms to 1.18 s, and the [bug] Web player stalls with an embedded PGS track on uncached remuxes on network storage #4199 reporter's storage took seconds per read.S_TEXT/WEBVTT) have no demux to fall back to, so they don't give way.demuxAndKeep, which keeps the track; jellycompat and translation through their own demux. The prefetch skips the track for an hour, as it does after any failure. A PGS window open to the end whose whole read gave way warms the cached.supwith the demux, as fix(playback): demux a subtitle window the file's index can't read in time #4272 does after a slow window, instead of reading through the index again. Burn-in staging and HLS rendition windows are unchanged: staging has its own 15-second bound, and a rendition window reads only the cues from its segment's start.Validation
Reproduced live on an isolated dev sandbox. Direct play of a 7.3 GB, 40 Mbit/s H.264 file with PGS tracks, its library on a FUSE mount that models remote storage with a read cache: a new download stream waits 0.8 s and fetches 16 MiB past the read, all streams share 40 MB/s, and fetched blocks are cached. Each run started cold (no kept track, no cached subtitle, empty storage cache). A client read the media stream and requested the whole PGS track with a 30-second stall timeout and the web player's retry backoff, for 150 seconds. Builds alternated between
main(7115ee702, which includes fix(playback): demux a subtitle window the file's index can't read in time #4272) and this change:mainThe playback stream needs 120 s of video in 120 s to keep up.
On
mainthe server log shows each subtitle request abandoned after 30–50 s with 0 bytes, and the read handing the request to the demux after 90 s while it kept reading. With the change, the read gave way 5–7 s after the request, and the storage settled to one or two streams.Playback starting 3.6 GB into the file, where the demux and the playback can't share the storage cache, three alternating runs each:
main43.4 s of video by 120 s (39.5–45.0) and no subtitle bytes; this change 458.4 s (418.4–461.3), with the first subtitle byte at 12.7 s (12.2–14.7).On one more run the demux kept the track (
method=ffmpeg, 559 packets,complete) about 3 minutes 40 seconds after the request, after its client had left. A second whole-track request then got the whole track in 0.1 s.A new test drives a whole read over a reader that takes a second per read. With
SlowReadthe read stops after its first round instead of reading every cue, and a track whose reads all went out in that round still comes back whole. The test can't run onmain, where the option doesn't exist; with the refusal disabled it fails (64 reads instead of at most 32). The live runs above are the proof of the fix. A new row in the slow-window test covers the PGS warm after an open-ended window gives way: it fails on the previous head (the warm read the whole track once more) and passes now.Go build, vet, gofmt,
go mod tidy -diff,make lint-changed,make lint-router-recovery,make verify-local-paths,make verify-size-ratchet,make verify-bidiandmake verify-case-collisionspass.make test-gopasses exceptTestCopyRemuxSubtitleRenditionRealFFmpegandTestRunStatsWithRealFFmpeg, which fail the same way onmainwith the test host's FFmpeg 6.1. Two tests in packages that don't call the changed code (librarymonitor,streamtelemetry) failed once under the full suite's load and passed ten times in a row alone. Web and contract checks don't apply: nothing underweb/orcontracts/changed.Evidence: https://evidence.siloserver.org/r/silo-server/keptsub-whole-track-slow-storage/
Risks
Checklist
Follow-ups
maintoo (a file without Cues demuxes at once); this PR makes them start sooner on slow storage. A separate fix will bound concurrent foreground subtitle demuxes.AI Disclosure
🤖 Generated with Claude Code
Note
Fall back to whole-track demux for embedded subtitles when random reads are slow
ReadOptions.SlowReadand theErrSlowReadssentinel in read.go.fileReader.ReadAttracks the duration of its latest 16 reads in a ring; once their average exceeds the limit, new reads returnErrSlowReadswhile reads already in progress finish.keptsubsets a 500 ms average latency threshold for whole reads (windows open to the end and whole-track copies), but not forIndexOnlytracks, which keep being read through the index as before. See store.go.SubtitleCache.serveWindowedSUPin subtitle_cache.go treatsErrSlowReadslike the existing slow-window error and falls back todemuxAndKeep.Macroscope summarized 83ba1fe.