Skip to content

Playback: retry (don't error) on transient segment/manifest failures so server transcode restart-resilience works #3

Closed

Description

@CoffeeKnyte

Problem

When the Silo server restarts briefly (e.g. a deploy / docker compose down/up, ≤ 60s) while someone is watching server-transcoded video, the Android app shows a fatal playback error instead of riding through the blip. The player has a healthy buffer (up to ~120s) and could keep playing while the server comes back, but the first network request that fails during the outage kills the session and playback stops — the viewer sees an error, not a brief pause.

This matters now because the server side has been made restart-resilient: it persists a tiny "recipe card" per transcode session and reconstructs the session on the next request after a restart, so the client's next segment/manifest request succeeds again once the server is back. That work is invisible unless the client retries instead of erroring.

Server-side change (context / tracking): Silo-Server/silo-server#174
(See the spec's "Operating model" and Preconditions — P3: client retry/backoff and Risk #4: client doesn't retry — which call out silo-android/silo-apple as the coordinated follow-up.)

Scope note: the server currently delivers this for the HLS transcode path; remux and the Jellyfin-compat path are in-target but not yet implemented server-side, so this issue is about the transcode path.

Solution

The client must treat a transient request failure during an outage as retryable, not fatal, and keep draining its buffer until the server returns. Audit of the current code (read-only) found the media path has no retry beyond a single 401 auth refresh:

Stack: AndroidX Media3 / ExoPlayer + a dedicated OkHttp client for media (OkHttpDataSource.Factory → AuthenticatedDataSourceFactory); session/control over Ktor REST. No WebSocket.

Findings (file:line):

  • No segment/manifest retry. No custom LoadErrorHandlingPolicy is set (ContinuumPlayerFactory.kt:96-116); the stock DefaultLoadErrorHandlingPolicy gives ~3 retries over a few seconds then a fatal PlaybackException, ignores Retry-After, and can't span a 60s outage. The media OkHttp interceptor only retries 401 (MediaAuthInterceptor.kt:55-56); no retry interceptor in PlayerOkHttpClient.kt:17-27.
  • Fatal-vs-transient classification is the crux and it fails. onPlayerError is wired to a no-op (PlaybackPreflightListener.kt:23,38-40; constructed without onError in PlayerScreen.kt:233-237 and TvPlayerScreen.kt:226-228), so a single failed media request goes terminal and the ViewModel never even learns of it.
  • Buffer is fine but wasted. DefaultLoadControl is 60s/120s with prioritizeTimeOverSizeThresholds (ContinuumPlayerFactory.kt:103-111) — the player could coast through the outage, but the missing retry tears the session down first.
  • Existing REST outage loop is on the wrong channel. PlaybackSessionLifecycle.kt:236-282 (beginOutageRecovery) has good exp-backoff health probing, but it fires only on ApiResult.NetworkError from the progress-report call (:194-197); a 503/404 returns ApiResult.Error and is just logged (:198-201), and it never feeds back into ExoPlayer.

Proposed changes

  1. Add a custom LoadErrorHandlingPolicy (highest priority) wired via DefaultMediaSourceFactory(...).setLoadErrorHandlingPolicy(...) at ContinuumPlayerFactory.kt:96. For InvalidResponseCodeException with 404/500/502/503/504 and for connection errors (SocketTimeoutException/ConnectException/SocketException), return a positive backoff (not C.TIME_UNSET) and a large retry count while elapsed outage time is within a ~90s window; honor Retry-After from the response headers.
  2. Stop treating media onPlayerError as a no-op. Pass a real onError in PlayerScreen.kt:233 / TvPlayerScreen.kt:226 that, for transient I/O codes (ERROR_CODE_IO_BAD_HTTP_STATUS, ERROR_CODE_IO_NETWORK_CONNECTION_FAILED/TIMEOUT) within the outage window, calls controller.prepare() to re-request the (now-reconstructed) manifest/segments instead of surfacing a fatal error; only show a fatal error after the recovery deadline or for non-I/O codes.
  3. Broaden the REST outage trigger in PlaybackSessionLifecycle.kt:192-203 to also start recovery on ApiResult.Error with 502/503/504 (and honor Retry-After for the first probe delay).
  4. (Optional, defense-in-depth) a small bounded retry interceptor in PlayerOkHttpClient.kt for idempotent GETs on 502/503/504 honoring Retry-After.

Acceptance criteria

  • With a ~120s buffer, restarting the server (≤60s) mid-transcode playback results in seamless or at most a brief stall, never a fatal error, with playback resuming automatically.
  • Segment/manifest GETs retry on connection failure, 5xx (esp. 503), and 404, honoring Retry-After.
  • Verified by: kill/restart the server (or block the port) for ~45–60s during transcoded playback and confirm recovery.

AI-use disclosure

Drafted with AI assistance (read-only audit of the client + server spec, synthesis).

Activity

  1. added
    bug
    triaged
    and removed
    triaged
    on Sep 20, 2026
  2. added theissue type on Sep 20, 2026
  3. removed
    bug
    on Sep 20, 2026
  4. CoffeeKnyte commented on Oct 28, 2026

    @CoffeeKnyte
    Author

    Fixed on main. Media loads now go through SiloMediaLoadErrorHandlingPolicy (android-shared/.../player/MediaLoadRetryPolicy.kt), set on both the default and HLS source factories in SiloPlayerFactory.kt:

    • 404, 5xx gateway statuses, and timeout or connection errors are retried for up to 90 seconds, backing off 1, 2, 4, then 8 seconds.
    • Retry-After is honored.
    • A transient player error reopens the same route instead of failing.

    This landed in #36 and was refined in #115, so a brief server restart during transcoded playback should ride through on the buffer. Each HLS segment is its own load and gets a fresh retry window. The remaining restart problem, a second restart in one direct-play session, is tracked in #586.

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

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions