Skip to content

Embedded subtitle fetches stall up to 120s: the 600s extraction window is inert and truncations log as status=200 #423

Closed

Description

@CoffeeKnyte

Problem

Turning on subtitles can stall for two full minutes, and on the web player it happens again every ten minutes.

When a viewer picks a subtitle track that lives inside the video file (rather than as a separate .srt file next to it), the server has to dig the text out of the video before it can send it. On a big, high-bitrate film sitting on network storage, that digging is slow — and it is far slower than anyone realised.

What this looks like to people:

  • In the browser, subtitles appear, play for about ten minutes, then freeze on the last line and stay frozen for up to two minutes before catching up. Then it happens again. And again. The player re-fetches subtitles roughly every ten minutes of playback, so a viewer of a two-hour film pays this toll a dozen or more times.
  • On Android/TV and Apple clients, subtitles simply don't show up for up to ~40 seconds after you turn them on. Once they appear, they're fine for the rest of the film — those clients ask once and keep everything.
  • Subtitles that are separate files alongside the video are always instant (all such requests finish in well under a second). So the problem is invisible to anyone testing with sidecar subtitles, and only bites on embedded tracks.

Measured over 41.6 hours of production traffic (2026-07-15 → 2026-07-17) on /api/v1/stream/{session_id}/subtitles/{track}:

client requests p50 p95 max ≥10s
browser (web player) 220 72ms 120,021ms 121,470ms 45
native (Android/TV) 42 145ms 9,566ms 41,607ms 2
sidecar/external files 118 — — all <1s 0

The two-minute ceiling is not a coincidence, and it's worse than a stall. 120s is the server's own connection write timeout. It cuts the response off mid-sentence. Because the server has already declared the request successful by the time it starts sending text, a subtitle file that got chopped in half is recorded in the logs as a perfectly successful request. Every dashboard we have says this endpoint is healthy. Viewers are getting truncated subtitle tracks and nothing anywhere reports an error.

What previous reviews missed.

The server has a feature that is supposed to prevent all of this: it only asks for a ten-minute slice of subtitles around wherever you are in the film, instead of the whole track. That feature does not work. The instruction that limits the slice is passed to ffmpeg in a position where ffmpeg silently ignores it — so every single request quietly reads from the seek point to the end of the file, no matter what limit is requested.

This survived two rounds of code review, on both sides, because everything reads correct:

  • The code comment states plainly that it bounds how much of the file is read.
  • The flag really is there in the command, exactly as the comment describes.
  • The unit test asserts the flag is present — and it passes.
  • The log line faithfully reports the window that was requested.

So reviewers checked intent against intent and found agreement. Nobody ran the command. Only actually executing ffmpeg against the production binary shows that asking for 30 seconds, asking for 300 seconds, and asking for nothing at all produce byte-identical output, all ending at the final cue of the film.

A related process failure is worth recording: an early investigation grepped the API request logs for the window parameters and concluded no client was sending them. Those logs have no query-string field at all — the greps could never have matched anything. The conclusion was drawn from a search that was structurally incapable of returning a result, and it pointed the investigation at the wrong client for a while.

And the obvious fix is a trap. The natural reaction is "just move the flag so the limit works." That would break subtitles on every non-browser client. The Apple and Android apps both fetch a subtitle track exactly once and keep the whole thing; they have no concept of re-fetching. They work today because the limit is broken and they accidentally receive complete tracks. Enabling the window as written would silently kill subtitles about ten minutes into every film on iOS, tvOS, macOS and Android — and the accidental whole-track behaviour has, in effect, become the contract those clients are written against.

Shrinking the window would be worse still: the web player hardcodes its ten-minute stride and advances blindly without checking what it actually received, so a server-side window smaller than ten minutes produces a subtitle blackout in the gap.

Technical detail

  • streamExtractArgs (internal/playback/subtitle_stream.go:161-168) passes -t as an input option. ffmpeg ignores it for these extracts. Only -ss takes effect, so cost is (duration − seek) × bitrate — which the logs confirm exactly: seek=8s/130s/519s → ≥60s; seek=7797s/8392s/8987s → <1s. Every 120s outlier is a ≥28 Mbps remux.

  • Measured against the production binary (ffmpeg 7.1.4-Jellyfin, /usr/lib/jellyfin-ffmpeg/ffmpeg inside the silo container):

    command wall bytes last cue
    -ss 4000 -t 30 -i F 5s 38,562 02:10:04
    -ss 4000 -t 300 -i F 6s 38,562 02:10:04
    -ss 4000 -i F (no -t) — 38,562 02:10:04
    -t 600 -i F (seek 0) 86s 83,092 02:10:04

    -to as an output option does bound correctly (-ss 4000 … -to 4600 → 1s, 9,170 bytes, last cue 01:16:32) — but see the client constraint below.

  • The 120s ceiling is WriteTimeout: 120 * time.Second (cmd/silo/main.go:2389). WriteHeader(200) has already been called (internal/api/handlers/stream.go:576) and the logging middleware records that status (internal/api/middleware/request_logger.go:29), hence status=200 on a truncated body.

  • Client constraint, from scans of the sibling repos:

    • silo-apple — SidecarSubtitleFetcher.swift:48-95 issues a single GET; SubtitleSession.swift:244-287 caches the whole response and never re-requests. No position=/duration=.
    • silo-android — SubtitleTrackMerge.kt:56 builds a bare URL handed to Media3 as a MediaItem.SubtitleConfiguration (SiloPlayerFactory.kt:413); ProgressiveMediaSource fetches once and parses every cue. No re-fetch.
    • web windows correctly — web/src/player/hooks/useSubtitleTracks.ts:79 sends position=, advancing by 595 (WINDOW_DURATION 600 − WINDOW_OVERLAP 5), the exact stride seen in production.
  • Distribution is by codec, not by what it first appears: 135 of 143 embedded requests are subrip. ASS is incidentally safe only because IsASS blocks -ss.

  • Ground truth for windowing is seek_seconds in the handler log (118 of 143 non-zero), not the API request log, which carries no query field.

Possible directions

Not a decision, just the option space as it currently looks:

  • Cache the extract, change nothing a client sees. Keep whole-track delivery and make it cheap. SubtitleCache (internal/playback/subtitle_cache.go) already implements this shape for PGS; text was excluded on the assumption that "VTT is already windowed and fast", which the inert -t makes false. Windowing a cached 83 KB VTT costs ~52ms versus ~16s against the original 27 GB remux. Does not help the first viewer of a file+track.
  • Make the window real (-t → -to) — blocked until silo-android and silo-apple send position=/duration= and re-fetch on coverage exhaustion. Requires coordinated client work.
  • Extract embedded tracks to sidecars at scan time, putting every subtitle on the already-instant external path and retiring on-demand extraction entirely. Likely the real endgame.

Whatever the direction, the inert -t must not be "cleaned up" in isolation — its comment describes a bound that does not exist and needs correcting in place, or the next reader will fix the flag and break both native clients.

Related

  • Non-finite ?position= (+Inf parses and passes the >= 0 check, reaches ffmpeg and fails after the 200) is a separate genuine bug found during this investigation.
  • The status=200-on-truncation masking is largely inherent once headers are committed (LogSubtitleStreamError, internal/playback/subtitle_stream.go:273-277, documents it as deliberate). A rolling deadline like the one full downloads use (internal/httpstream/rolling_deadline.go) may be the right follow-up.
  • The standalone proxy has separate uncached ASS/text extraction paths (internal/proxy/server.go:273, :286).

AI-use disclosure

Investigation and this write-up were prepared with AI (Claude Code) assistance; client impact was assessed by subagent scans of silo-apple and silo-android.

Activity

  1. added
    bug
    go
    on Jul 17, 2026
  2. Quick104 commented on Sep 11, 2026

    @Quick104
    Contributor

    Closing: addressed by merged #938 (Related issue: #423; explicit-window repair, caching, interrupted-response handling).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggo

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions