fix(instant-stream): cap time-to-first-byte so the player can't hang#93
Merged
Merged
Conversation
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>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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'scontroller.initialize()never returns → infinite spinner. (yt-dlpresolve already had a timeout; this is the proxy's first-byte gap.)Fix
Wrap only the initial
client.sendinasyncio.timeout(20s)(_FIRST_BYTE_TIMEOUT_SECONDS). On a stall it raisesInstantStreamError→ 502, 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