Skip to content

fix(io): keep the window across a bounded-range continuation (#295) - #302

Merged
superuser404notfound merged 1 commit into
mainfrom
fix/295-range-boundary-refetch
Aug 4, 2026
Merged

superuser404notfound merged 1 commit into
mainfrom
fix/295-range-boundary-refetch

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

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. startPersistentConnection then reset winStart to that offset and dropped the window with it, which for the refill is up to winLowWater (8 MB) of delivered but undrained data. The very next read sat below winStart, 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 fill line, 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.

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.

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

Issue295RangeBoundaryRefetchTests drives 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 logs

bytes=0-20971519          initial range
bytes=20971520-54525951   #220 frontier refill
bytes=12582912-16777215   re-fetch
bytes=16777216-20971519   re-fetch

exactly winLowWater of re-fetched bytes, in two blocking detour fetches per boundary.

Full suite green (1492 tests, 222 suites, plus the XCTest targets).

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
@superuser404notfound
superuser404notfound merged commit 0d6d356 into main Aug 4, 2026
3 checks passed
@superuser404notfound
superuser404notfound deleted the fix/295-range-boundary-refetch branch August 4, 2026 09:11
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