Skip to content

Recover progressive direct play transparently after a proxy terminates an idle HTTP stream #80

Closed

Description

@Quick104

Summary

Progressive direct-play playback must treat the underlying HTTP response as disposable. If a reverse proxy terminates a response while Media3 is intentionally not reading because its playback buffer is full, Android should reopen the stream at the exact byte offset with Range and continue without surfacing a player error or remounting the media item.

This is the client-side fix that lets Silo work behind stock nginx/OpenResty configurations without requiring operators to raise send_timeout to an hour.

Incident shape

A Shield downloaded an original-quality stream much faster than playback and filled Media3's buffer. Media3 correctly stopped reading from the socket. A reverse proxy using nginx's default client-facing send_timeout 60s terminated the no-write-progress HTTP/2 stream. The failure was not observed until the buffer drained a few minutes later:

StreamResetException(INTERNAL_ERROR) → ERROR_CODE_IO_NETWORK_CONNECTION_FAILED → same-route player remount → visible playback hiccup.

This is a transport-lifecycle event, not a decoder failure or evidence that the buffer was empty when the proxy closed the response.

Current implementation

Source baseline reviewed: d19cfb8483a5a7b52d46ab14138a2d435e3e3070.

Proposed PR scope

  1. Make mid-body transport failures retryable inside Media3 for range-resumable progressive direct-play sources:
    • HTTP/2 stream reset / connection shutdown
    • premature EOF after byte progress
    • equivalent idempotent GET connection failures
  2. Use LoadErrorInfo.loadEventInfo.bytesLoaded (and the selected delivery type/capability) to distinguish a resumable mid-stream failure from an initial connection failure or non-resumable progressive remux.
  3. Let Media3 reopen from its current DataSpec.position; do not route the successful recovery through the ViewModel remount/replan ladder.
  4. Keep the retry window and backoff bounded. Do not retry authentication/authorization failures, unsupported range responses, parser/decoder failures, or non-idempotent requests.
  5. Add structured diagnostics for:
    • original exception/cause
    • bytes loaded before failure
    • requested resume offset
    • retry attempt/delay
    • whether the error escaped to Player.Listener.onPlayerError
  6. Audit SiloLoadControl.calculateTargetBufferBytes: measured network capacity (latestBitrateEstimate) must not inflate a progressive media buffer target when an actual media bitrate is available. This may be a follow-up PR if keeping the recovery change focused.

Acceptance criteria

  • A proxy-terminated HTTP/1.1 or HTTP/2 direct-play response resumes with a new Range request at the correct next byte.
  • The player timeline and playback position remain continuous; no setMediaItem + prepare, protocol replan, black frame, or user-visible error occurs.
  • Retry is bounded and cannot loop indefinitely when the origin repeatedly fails without progress.
  • A server that ignores Range, returns invalid Content-Range, changes the entity, or returns 401/403 produces the appropriate existing recovery/error path rather than silent corruption.
  • HLS segment retry behavior from Playback: retry (don't error) on transient segment/manifest failures so server transcode restart-resilience works #3 remains intact.
  • Phone and Android TV use the same policy and both pass focused tests.

Verification

Automated

Use a full Media3 progressive-source test (not only a policy unit test):

  1. Serve a valid seekable fixture with Accept-Ranges: bytes.
  2. Terminate the first 206 response after meaningful byte progress using both premature EOF and an HTTP/2 reset-equivalent failure.
  3. Assert the next request contains the exact expected Range.
  4. Assert playback reaches the end without a player error or media-item remount.
  5. Cover no-progress retry exhaustion, mismatched Content-Range, 401/403, 416-at-EOF, and non-resumable delivery.

Device soak

Put the development server behind nginx/OpenResty with a short client-facing send_timeout, allow a Shield to fill its buffer and stop reading, and verify multiple close/resume cycles during a long high-bitrate title with no visible hiccup.

Non-goals

  • Replacing progressive original-file direct play with HLS.
  • Server-side byte pacing or payload heartbeats.
  • Depending on a one-hour reverse-proxy timeout.

Activity

  1. added
    bug
    on Jul 21, 2026
  2. Quick104 commented on Sep 4, 2026

    @Quick104
    ContributorAuthor

    Implemented by PR #99. Progressive original-file playback can retry mid-body transport failures inside Media3 and reopen at the byte offset, with bounded retries and an ETag/If-Range guard, without routing successful recovery through a player remount or protocol replan. Phone and TV share the policy.

    The merged PR records a real ExoPlayer/MockWebServer integration test proving ranged recovery through playback completion, failure-path coverage, both app builds, and a Galaxy S26 Ultra server-side range check. PR #147 subsequently bounded the buffer's idle window and records testing against the restored 60-second proxy timeout.

    Verified the recovery implementation and integration tests remain on main at 8791af20, whose unit-test check passes. No new device soak was run during this cleanup. Closing as completed.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions