Skip to content

fix(instant-stream): cap time-to-first-byte so the player can't hang#93

Merged
windoze95 merged 1 commit into
mainfrom
fix/instant-stream-first-byte-timeout
Jun 29, 2026
Merged

fix(instant-stream): cap time-to-first-byte so the player can't hang#93
windoze95 merged 1 commit into
mainfrom
fix/instant-stream-first-byte-timeout

Conversation

@windoze95

Copy link
Copy Markdown
Owner

Bug

Tapping some episodes (e.g. a long Kill Tony) sometimes just spins on "Preparing your video…" forever.

Root cause

The instant-stream proxy intentionally disables the read timeout (read=None) so a long playback isn't cut off — but that also left the initial upstream fetch untimed. If the source accepts the TCP connection and then stalls before sending the response, await client.send(...) hangs indefinitely → the endpoint never responds → the client's controller.initialize() never returns → infinite spinner. (yt-dlp resolve already had a timeout; this is the proxy's first-byte gap.)

Fix

Wrap only the initial client.send in asyncio.timeout(20s) (_FIRST_BYTE_TIMEOUT_SECONDS). On a stall it raises InstantStreamError502, so the client falls back to the preview path instead of hanging. The body generator stays untimed, so legitimate long playback is unaffected.

Paired with the client-side init timeout in windoze95/nullfeed-flutter#58.

Test

test_instant_stream_first_byte_timeout_502 — a mock upstream that sleeps past the (patched-small) budget returns 502. Full instant-stream suite: 8 passed; ruff + mypy clean.

🤖 Generated with Claude Code

The proxy uses read=None (so long playback isn't cut off), which also left the
INITIAL upstream fetch untimed: a source that accepts the connection then stalls
before responding would hang the request forever, leaving the client stuck on
"Preparing your video…". Wrap only the initial `client.send` in
`asyncio.timeout(20s)` → surfaces as a 502 (InstantStreamError) so the client
falls back, while the body stream stays untimed.

Test: a stalled upstream (mock that sleeps past the budget) returns 502.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@windoze95 windoze95 merged commit c7cbd84 into main Jun 29, 2026
5 checks passed
@windoze95 windoze95 deleted the fix/instant-stream-first-byte-timeout branch June 29, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant