Skip to content

Sequential media GETs reuse the HTTP/1.1 demux socket - #89

Merged
GLinnik21 merged 4 commits into
plxnative:mainfrom
MrcRjs:fix-playback-keep-alive
Sep 14, 2026
Merged

GLinnik21 merged 4 commits into
plxnative:mainfrom
MrcRjs:fix-playback-keep-alive

Conversation

@MrcRjs

@MrcRjs MrcRjs commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Media socket is closing after every sequential GET. Each HLS segment and each Original range paid a new TCP handshake for a server that already speaks HTTP/1.1 keep-alive. That shows up as a stall, not as tidy cleanup.

What this PR changes

Media requests now leave Connection off so PMS can keep the fd. The next GET to the same peer reuses it once the previous body is fully read. An unread body, leftover buffer bytes, HTTP/1.0, or an explicit Connection: close still opens a new socket.

If the peer idles out or half closes, we redial once instead of failing the GET. A shutdown of a live keep-alive fd is teardown of that open. We do not dial a replacement the shutdown cannot reach.

Chunked responses consume trailers before reuse, so leftover bytes are not mistaken for the next status line. Incomplete trailers close the socket.

crate::http is unchanged: it still sends Connection: close and still closes a one shot stream. HTTPS media reuses the libcurl multi across playlist and segment URLs. A Range seek still closes first, so tests can still tell a seek from a reused GET by counting accepts.

Keep-alive only helps if the socket stays readable. Original parks aq_push on the AVIO thread, and a full AU queue used to let the TCP window collapse (or let PMS FIN us). While parked we now drain available bytes into the bounce buffer. That is why reuse survives a backlog.

Docs that still said media used Connection: close are updated. Main-thread control-plane freezes are the same as before.

Verification

Host tests in stream.rs, aq.rs, http.rs, curlio.rs, and ff.rs cover:

  • two drained HTTP/1.1 and chunked GETs share one accept

  • Connection: close, an unread body, HTTP/1.0 keep-alive, and incomplete trailers do not reuse

  • named chunked trailers reuse; poisoned leftovers do not

  • media sequential GETs omit Connection: close; control-plane plaintext still sends it

  • shutdown of a live keep-alive fd does not dial a replacement

  • idle peer close redials the next GET; teardown after that close does not

  • drain returns immediately when the body is done or the peer stalls mid-chunk

  • mid-body EOF is a transport error on both read and drain

  • aq_push_with_drain runs while the consumer holds the queue full

  • curl sequential GETs reuse the multi for a second GET

  • make check

  • CARGO_INCREMENTAL=0 cargo +nightly check --manifest-path rust-modules/Cargo.toml --lib --no-default-features

Reuse and drain are host-visible. Whether Original holds a live socket across a real AU backlog still needs a TV play.

@GLinnik21 GLinnik21 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple of nasty edge cases here, and the local pipeline still does not exercise connection reuse. Please fix these before merging.

Comment thread rust-modules/src/stream.rs Resolved
Comment thread rust-modules/src/stream.rs Resolved
Comment thread rust-modules/src/stream.rs Resolved
@MrcRjs

MrcRjs commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

There are a couple of nasty edge cases here, and the local pipeline still does not exercise connection reuse. Please fix these before merging.

@GLinnik21 Agree. The live-fd reuse path already captures interrupted across reset_fields. The redial-after-Transport path does not, drain can stall on split chunked trailers, and tests/serve_fixtures.py still answers Connection: close, so the pipeline never reuses. Will fix those three and push.

@MrcRjs
MrcRjs force-pushed the fix-playback-keep-alive branch from 6a0a30c to 7823a55 Compare September 13, 2026 16:53
…mprove connection reuse logic, and add tests for keep-alive behavior in media GET requests.

Signed-off-by: Marco Rojas <[email protected]>
@MrcRjs
MrcRjs force-pushed the fix-playback-keep-alive branch from 8da27e4 to e447ff8 Compare September 13, 2026 17:27
@MrcRjs
MrcRjs requested a review from GLinnik21 September 13, 2026 17:27

@GLinnik21 GLinnik21 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The retry race is fixed, but the broader entry race is still here.

Comment thread rust-modules/src/stream.rs Resolved

@GLinnik21 GLinnik21 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The real TV run exposed one fixture-server regression from enabling keep-alive.

Comment thread tests/serve_fixtures.py Resolved
@GLinnik21

Copy link
Copy Markdown
Collaborator

For device verification, you can ask an agent to run the universal synthetic player tier (./tests/run.py). It serves generated dummy media and covers Original, HLS, Auto/ABR, network shaping, seek, EOS, and other playback paths without needing a Plex library. The real PMS cases under --server were written around my private library because I did not expect external contributors, so I do not expect you to reproduce those. If you can think of a better portable way to verify this end to end, feel free to propose it.

@MrcRjs

MrcRjs commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

For device verification, you can ask an agent to run the universal synthetic player tier (./tests/run.py). It serves generated dummy media and covers Original, HLS, Auto/ABR, network shaping, seek, EOS, and other playback paths without needing a Plex library. The real PMS cases under --server were written around my private library because I did not expect external contributors, so I do not expect you to reproduce those. If you can think of a better portable way to verify this end to end, feel free to propose it.

Thanks! Yeah I've just doing some manual testing along with running some partial tests. Long term we can probably looks at something like https://github.com/iwalton3/stdjflib or our plex-variation to run a full regression and programmatically generate a PMS test library.

@GLinnik21

Copy link
Copy Markdown
Collaborator

programmatically generate a PMS test library.

As you can see, I'm doing a huge refactoring of the UI architecture. Turns out GPT Astra generates such mocks on the fly 😅 to check behaviour

…ance for Linux, and add tests for in . Update struct in to manage trailer line content and improve connection handling logic.

Signed-off-by: Marco Rojas <[email protected]>

@GLinnik21 GLinnik21 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: I ran the same two cases against current main (6073ae00cfe17e3cea58d19e50e734f4fe9cc2c5) on the same TV, network, and fixture pack. Both fail there too, with essentially the same numbers:

  • pipe_replay_after_eos: again 0 replay: lines and one body instead of two.
  • pipe_abr_down_collapse: again only pos_climb fails — 37s instead of the required 45s (the PR run reached 36s).

So these failures were not introduced by #89 and should not block it. The PR run itself finished 42/44; all keep-alive, HLS/ABR wire, and Range-reuse checks passed. Sorry for the noise — the baseline control clears the PR.

@GLinnik21
GLinnik21 dismissed their stale review September 14, 2026 13:47

Both device failures reproduce on main under the same conditions, so they were not introduced by this PR.

@GLinnik21
GLinnik21 merged commit b074943 into plxnative:main Sep 14, 2026
2 checks passed
GLinnik21 added a commit that referenced this pull request Sep 16, 2026
Merges #92 (trailer playback from detail), #89 (sequential media GETs
reuse the HTTP/1.1 demux socket), #94 (Windows WSLg/Linux simulator
support), the landing-page site/ tree and other unrelated origin/main
work into this branch's own commit (13316a8, "fix: scrub bare host=
key/value hostnames from logs"), resolving each conflicted file by
preserving both sides' intent:

- rust-modules/src/player/ffi.rs, mod.rs, pump.rs, threads.rs,
  webos.rs, src/starfish.c, rust-modules/src/app/playback.rs: kept
  both branches' independent additions (resolved in earlier sessions
  on this branch).
- rust-modules/src/player/shared.rs: kept both sides' distinct
  `LoadCall` enum members; git's auto-merge had silently produced a
  duplicate enum definition with no conflict markers, caught only by
  compiling.
- rust-modules/src/player/engine.rs: removed a duplicate
  `load_in_flight_tests` module that auto-merge combined from both
  sides without markers.
- rust-modules/src/plex/session.rs: wired `trailer_autoplay` (our
  side) into `CanonicalSessionPreferences`, `split_public()` and
  `join_canonical()` (origin/main's refactor of the same struct),
  which the auto-merge had left half-connected.
- rust-modules/src/screens/registry.rs: recombined the
  `SCREEN_SHAPES_PIN` changelog (already merged cleanly as text) and
  bumped the pin constant to the merged tree's real hash
  (0xb462_145d_9477_05de -> 0x0e66_311c_e4f1_0769), documenting the
  bump as the union of independent changes rather than one feature.

Two more fixes were required for the merged tree to pass verification
at all, both confirmed to be pre-existing defects already present on
origin/main's own fetched tip (227d981) rather than anything this
merge produced:
- ci/check-deps.sh: restored the missing closing brace on
  `strip_strings_and_comments()` (a bash syntax error on
  origin/main's tip that broke `make check`).
- ci/allow/sibling-migration.txt: replaced literal, unresolved
  stash-conflict markers baked into origin/main's own committed
  content with this branch's already-clean, closed-out version (count
  0, matching a dangling repair commit b58db338 that fixed the same
  file identically but was never merged into origin/main).

One further fallout fix, found only by the fourth verification
command and unrelated to origin/main (the file does not exist there
at all): rust-modules/src/webos/jail_repair.rs's `expect(dead_code)`
condition on `Failure::Timeout` incorrectly required `devtriggers` to
be off; hostsim's `call_hbc` stub never constructs that variant
outside tests regardless of `devtriggers`, so `cargo check --features
hostsim` (as opposed to `cargo test`, which compiles the test module
that uses it) failed. Narrowed the condition to `hostsim` + `not
test`.

Verification, all green:
- make check: full host suite + make lint + ci/check-deps.sh + all
  package/dependency gates pass (exit 0).
- CARGO_INCREMENTAL=0 cargo +nightly check --no-default-features:
  passes.
- cargo +nightly check --features hostsim: passes (after the
  jail_repair.rs fix above).
- make (ARM cross-build, FLAVOR=debug): passes, produces pkg/plxnative
  and pkg/plxnative-storage.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01W3rkPgGB7xpjGgcPbfakaF
GLinnik21 added a commit that referenced this pull request Sep 23, 2026
…ive fetch (#209)

On the TV, `pipe_abr_down_collapse` froze the picture for 84.5 s when the link collapsed from 40 Mbps to 500 kbps on rung 20000. The same-encoder lookahead from #89 (`hls_prefetch_same_encoder`) fetched segment 11 with no stall guard. It also swallowed any error into requeue + Ok(None), while the ordinary fetch of the same cursor always armed the guard.

`hls_demux_segment` now takes one required `SegmentAcquisition` instead of an optional (deadline, guard) pair. The policy is sealed in `ff_acquisition.rs`:
- Cursor fetches are built only by `for_cursor(Option<&abr::Controller>)`, which samples the live reserve, floor and hold itself.
- Candidate transfers use `candidate(deadline)`, unchanged.
- All four callers are migrated.

Both fetch paths route `StallAbort` through one reducer, `hls_stall_abort_outcome`: requeue once, feed nothing, sample `.abandoned()`.

Regression tests drive the lookahead's real control flow. They went red under both reverts: an unguarded lookahead, and a swallowed abort.

On the TV, all 23 ABR cases pass. `down_collapse` logs `stall abort seq=11 … cause=terminal_reserve`, the freeze drops from 84.5 s to 5.8 s, and playback reaches 111 s. `make check` passes: 4199/4250/101, with 0 failed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants