Skip to content

fix(hls): stream segment bodies on the persistent HTTP/1.1 ingest, no 45 s exchange ceiling (#732) - #816

Merged
superuser404notfound merged 2 commits into
mainfrom
fix/732-streamed-segment-bodies
Oct 17, 2026
Merged

superuser404notfound merged 2 commits into
mainfrom
fix/732-streamed-segment-bodies

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

Follow-up to #732 after the paired device runs: the held HTTP/1.1 transport was fine on protocol and reuse, but its delivery semantics failed on slow origins.

What changes

  • Bodies are streamed. PersistentHTTP1Transport.open returns after the response head, and the body reaches the ingest FIFO as it arrives.
  • The carriage probe no longer downloads segment 0 whole. It reads the head and hands the open response to the producer.
  • No 45 s whole-exchange ceiling. 45 s now covers only the wait for a response head. A body ends on its size limit or on 30 s without a byte. Expiry of the old ceiling surfaced as NSPOSIXErrorDomain Code=60; a stall now reads body stalled, no bytes for 30 s after <received>/<expected> bytes in <elapsed> s.
  • One request per origin at a time. A request claims its origin, and the next one waits until that connection is back in the pool or closed, so a seek never opens a second connection beside a response still in flight.
  • Bounded drain on seek. An abandoned body with at most 2 MB left, arriving within 3 s at the rate seen so far, is drained and its socket kept. Otherwise it closes at once.
  • Backpressure at segment boundaries. With the FIFO full the current segment is read to its end (one segment over the ceiling, as before), so a pause leaves the connection idle between requests, not mid-body.
  • The h2 ingest session's 45 s resource timeout is lifted the same way.

Measured

aetherctl play --held-connection against a loopback keep-alive origin with a shared rate limit, 3 x 60 s HEVC-in-TS segments of about 11.6 MB:

rate main (bb351047) this branch
263 KB/s first frame at 177 s (probe and two engine repositions each download segment 0 whole) first frame at 45 s, plays through
200 KB/s probe dies at 45.1 s with Code=60 after 8.2 of 11.6 MB, session leaves the ingest ingest holds, first frame at 65 s, rebuffers only because the link is below the content rate

Tests

Issue732PersistentHTTP1Tests goes from 10 to 18 tests: streaming before the segment ends, the probe leaving segment 0 open, a drained seek on one connection with at most one response in flight, close on a large or slow remainder, the drain deadline, a stall error carrying its progress, a steady slow body that outlives the read timeout, a full FIFO letting the current segment finish while the next request waits, and a seek onto an encrypted first segment (hangs without the fix, verified). Full swift test: XCTest 778 and swift-testing 4614, exit 0.

Not in scope

  • The engine's own two repositions onto segment 0 right after the open still cost one connection each. This was already the case before this PR, and their cost is now a few hundred KB instead of a whole segment.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS

Vincent Herbst and others added 2 commits October 17, 2026 16:04
… 45 s exchange ceiling (#732)

Under heldSourceConnection the HEVC-in-MPEG-TS VOD ingest downloaded every
segment whole before the demuxer saw a byte, its carriage probe downloaded
segment 0 whole, and one 45 s deadline covered head and body together. On a
slow origin a large segment could not finish inside it, and the expiry
surfaced as the socket's own POSIX timeout (Code=60), naming neither cause.

- PersistentHTTP1Transport.open returns the response head and a Body read
  piece by piece; get() is open plus collect.
- The 45 s ceiling covers only the wait for a response head. A body ends on
  its size limit or on 30 s without a byte (typed .stalled with
  received/expected bytes and elapsed time).
- One request per origin at a time: checkOut claims the origin and the next
  request waits for the connection to be pooled or closed, so a seek never
  opens a second connection beside a response still in flight.
- An abandoned body with at most 2 MB left drains for up to 3 s and keeps
  its socket; a larger remainder closes it.
- The probe reads the head and hands the open response to the producer.
- With the FIFO full the current segment is read to its end, so a pause
  idles the connection between requests, not mid-body.
- The h2 path's 45 s resource timeout is lifted the same way.

Measured on a loopback keep-alive origin at 200 KB/s with 11.6 MB segments:
before, the probe died at 45.1 s with Code=60 and the session left the
ingest; after, the ingest held and played.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS
- A probe response the producer's run does not open with (a seek onto
  another or an encrypted first segment) is abandoned before any request.
  It held the origin's claim unread, so the next request waited forever.
- A request cancelled while it waited for the origin does not take the
  connection; its cancellation handler would close the drained socket.
- A seek drains an abandoned body only when the rest arrives within the
  drain deadline at the rate seen so far; a slow remainder closes at once
  instead of holding the next request 3 s and closing anyway.
- next() checks cancellation before marking a read in flight, so abandon()
  never waits on a read that does not happen.
- A refused or redirecting body is drained for at most 45 s.
- No extra copy of each chunk into the pending buffer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS
@superuser404notfound
superuser404notfound merged commit 17215ee into main Oct 17, 2026
10 of 12 checks passed
@superuser404notfound
superuser404notfound deleted the fix/732-streamed-segment-bodies branch October 19, 2026 09:09
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