Repository navigation
fix(io): keep the window across a bounded-range continuation (#295) - #302
Merged
Merged
Conversation
The #220 frontier refill opens the next range while bytes are still resident ahead of the read position, precisely so a range boundary does not become a stall. startPersistentConnection then reset winStart to that offset and dropped the window with it, which for the refill is up to winLowWater of delivered but undrained data. The very next read sat below winStart, took the backward branch, and re-fetched those bytes 4 MB at a time through the detour cache, blocking on the demux read thread. A request that begins inside the resident window, or exactly at its end, is a continuation rather than a reposition, so the bytes below it are kept. The narrow race where the old connection appends past the frontier the read loop computed truncates instead, which the new range re-covers and which never leaves a hole. connRequestedOffset carries the offset that was actually asked for, since winStart is no longer that offset once a continuation keeps its window. The 200-ignored-Range rejection and the from-zero size derivation read it. Witness: Issue295RangeBoundaryRefetchTests drives a real HTTP origin with a paced consumer (the shape playback has, where the transfer wins the race) across a bounded-range boundary and asserts no requested range overlaps another. Before the fix the origin logs bytes=0-20971519, bytes=20971520-54525951, then bytes=12582912-16777215 and bytes=16777216-20971519: exactly winLowWater of re-fetched bytes, in two blocking detour fetches per boundary. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01HX5zV3Fcf7Nzq4DYGdXvQE
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.
Closes nothing yet: leaving #295 open for the reporter's retest.
The defect
The #220 frontier refill opens the next bounded range while bytes are still resident ahead of the read position, precisely so a range boundary does not become a stall.
startPersistentConnectionthen resetwinStartto that offset and dropped the window with it, which for the refill is up towinLowWater(8 MB) of delivered but undrained data. The very next read sat belowwinStart, took the backward branch, and re-fetched those same bytes 4 MB at a time through the detour cache, blocking on the demux read thread.Why it surfaced now, and on this content
It needs a consumer slower than the transfer, which is what playback is: the range completes long before the window drains, so the refill fires with the full low-water amount still resident. A test that reads flat out drains the window as fast as it arrives, reaches the boundary with nothing undrained, and sees nothing, which is why the existing #220 coverage stayed green.
The reporter's asset is a 6.7 Mbps SD MPEG-2 source, so a 32 MB range comes around every 40 s. Their correlation run put every visible stutter within reaction time of an
[AVIOReader] detour fillline, at 40.2 s +/- 0.2 s spacing. The software path carries no read-ahead (frameAhead=0.00s), so a blocked read longer than a frame interval is a picture stutter rather than an invisible hiccup. A 1 Mbps source rotates every several minutes and is rarely caught in the act.The fix
A request that begins inside the resident window, or exactly at its end, is a continuation rather than a reposition, so the bytes below it are kept. The narrow race where the old connection appends past the frontier the read loop computed truncates instead; the new range re-covers that span, so it never leaves a hole.
connRequestedOffsetcarries the offset that was actually asked for, sincewinStartis no longer that offset once a continuation keeps its window. The 200-ignored-Range rejection and the from-zero size derivation read it.Peak footprint goes down rather than up: the discarded window used to come back as up to 32 MB of detour blocks on top of the new range.
Witness
Issue295RangeBoundaryRefetchTestsdrives a real HTTP origin with a paced consumer across a bounded-range boundary and asserts that no requested range overlaps another. Before the fix the origin logsexactly
winLowWaterof re-fetched bytes, in two blocking detour fetches per boundary.Full suite green (1492 tests, 222 suites, plus the XCTest targets).