Repository navigation
Key mode: every handle does a full TLS handshake, never a resumed session - #1297
Merged
Merged
Conversation
…sion `main` CI went red when `ubuntu-latest` moved from Ubuntu 24.04 (libcurl 8.5.0, OpenSSL 3.0.13) to 26.04 (libcurl 8.18.0, OpenSSL 3.5.5): `media_seeks_and_reopens_in_key_mode_each_do_their_own_handshake` and `media_key_mode_never_reuses_a_kept_alive_connection` failed on the first key-mode seek. Key mode confirms the remembered key itself, from the certificate chain libcurl keeps for `CURLOPT_CERTINFO` (`keypin::confirm`). libcurl's OpenSSL backend skips that chain for a handshake that resumed a TLS session (`Curl_ossl_check_peer_cert`: "Reused sessions do not have cert chains"), so a resumed key-mode handshake reads as a pin mismatch (rc 90) and the seek fails closed. Before libcurl 8.12 the session cache belonged to each easy handle, so the fresh handle every `CurlSource` attempt gets never found one. From 8.12 it belongs to the multi handle, which the source keeps across its attempts, so the next key-mode attempt resumed the last one's session. `keypin::apply` (the one place both planes set up key mode) now also sets `CURLOPT_SSL_SESSIONID_CACHE` to 0, beside `CURLOPT_FRESH_CONNECT` and `CURLOPT_FORBID_REUSE`: the handle neither resumes a session nor leaves one. The option has existed since libcurl 7.16.0, and it is applied before `VERIFYPEER` is lowered like the others, so a libcurl that refuses it leaves the handle strict. The TLS doubles now count the handshakes they were asked to resume (`Observed::resumed`), the two failing tests assert it stays 0, and `key_mode_session_tests` puts a shared session cache in front of any libcurl through a share handle (a control proves an OpenSSL-backed libcurl does resume over it, then key-mode transfers prove they do not). The desktop simulator's SecureTransport libcurl does not resume against the double, so the control skips there and the key-mode test is a smoke check; the Linux CI runners are where it can fail. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…on cache Review of the previous commit: the doc claimed strict and roots-mode handles "never read a certificate back", which is false for the control plane's learning handle. The true reasons are that a `CurlSource` reads no chain on those handles and the control plane's fresh easy handle per request shares no session cache. Also drop the claim that libcurl 7.53.1 keys a session by the pin (only 8.12+ does); key mode stores no session, so none can be offered to a verifying handle. Co-Authored-By: Claude Opus 5.5 <[email protected]>
GLinnik21
pushed a commit
that referenced
this pull request
Nov 10, 2026
## What broke Two defect classes, both found in field testing on a real television (LG webOS, armv7l) against a real PMS server (1.43.5): 1. **The retranscode stall** — the last unhandled retranscode path. #1285 and #1286 covered the transcode *seek* (cold resume admitted at the Feed start door, play given back through the startup runner). The remaining path is the initial *drop*: a title plays direct, the quality ladder drops it, the retranscode lands — and then nothing plays. The log shows the pre-Load Play refused, and no further Play is ever attempted; the native buffer caps out (`BufferFull`), `pos_ms` stays 0. 2. **Codec declaration kills** — a single title kills playback: The Last Duel (an AAC file declared eac3 — the 7.1/AAC kill class — the video sink wedges under audioSync); DTS titles refused at Load (the DTS family declared `dca` where the demuxer says `dts`); and stale PMS declarations lying on **both** codec axes at once, so the one-shot corrective retry spent its reload without a single frame playing. ## Why 1. Since #1274 a retranscode landing starts its new stream PAUSED and hands the first Play to the user's Resume (the feed_pump Deferred branch) — never through the runner's `Operation::Play` — so `startup_play_commanded` stayed false. `try_prime`'s startup gate (`startup_controlled && !startup_play_commanded`) then blocked the prime's post-Load retry **forever**: `play_initial_now`'s physical Play landed before the Load worker's Starfish call, was refused, and the code never tried again — hence `BufferFull` at the native cap. The physical native hold (claim_hold) and the viewer pause goal were also conflated, which is what Changes 1-3 of the first commit untangle. 2. `fill_direct_plan` declared the PMS track's `achosen` (or the file's default) where the demuxer actually feeds a different codec; a single-axis probe on a refused start corrected only the first axis it hit, leaving the second mismatched — the one-shot retry then fired on a start that was still wrong. ## The fix 1. The Deferred branch now **latches `startup_play_commanded` before firing `play_initial_now`**: if the Play is refused pre-Load, the prime stays armed (`Held{Initial}`, `user_held` cleared, `resume_acb_pending` set) and `try_prime` issues it once loadCompleted has passed and both lanes are primed; the Accepted path mirrors `resume_acb` to the player. Plus Changes 1-3: the physical hold (`OpenRequest.start_paused`) is decoupled from the viewer pause goal (`InitialPlayback.paused`), so the post-Load resume path can actually run the clock. 2. **Declare what the pipeline actually feeds** (no-pick → the file's default codec; pick → the picked track's codec), map the DTS family to `dts`, and probe **BOTH** declared-codec axes in one pass so a single corrective reload fixes them together. One-shot, failure-path only — nothing in the happy path changed. ## Tests - `plx_play_feed`: 300/300 pass; `plx_media` suite green, including the new 16-cell audio/video declaration matrix (the 7.1/AAC kill class). - **Live on tv01** — The Dark Knight: 4K direct → 480p drop → retranscode at 16 s; the pre-Load Play was refused, then `primed: v=791ms a=317ms runway=0ms -> Play` fired after loadCompleted, ACB play=1, position advanced 31.4 s → 49.5 s through the timeline end with ok=1 and no BufferFull. The initial-transcode regression path (direct → retranscode at start) is green: pos 24.6 s → 47.8 s, ok=1. - `make check` (cargo half), `make check-nodef` and the ARM cross-check: green. `make check-cargo` (clippy clean, 18 test binaries in parallel): 17/18 pass; the single failure (`app::adapters::session::tests::a_signin_after_signout_behind_a_read_only_mount_is_written`) did not reproduce — the full lib suite re-ran green (1281/1281, 99 s) and the same test passes in isolation on the sibling fifo-API branch. is a pre-existing harness race under this container's parallel load, not a regression from this branch (this diff touches play-feed, net and media route/pump code — no session/storage code). `make check-nodef` (`cargo check --lib --no-default-features --features play-uri,play-feed`): green. ARM cross-check (cortex-a9, NEON off, frame pointers, debuginfo): green. The python half of `make check` — see the host-only note below. - The first CI run on this head caught a real regression the local default-feature gates do not cover: `check-cargo-unit-hostsim` runs the hostsim suite, where `player::pump::flight_tests::an_automatic_direct_original_recovery_flies_without_pausing_the_stream` was red. The claim-landing tail recorded `set_reconfigure_pause_goal(!hold)` for EVERY landed claim — including hold-less ones — and a hold-less claim (the direct Original recovery, no PMS round trip) landed on a paused stream. Fixed in `00e0eb37b`: the play goal is recorded only for claims that actually held presentation; hold-less landings fall back to the stream's own transport state (`feed_start_paused` reads `readout().paused()` when no goal is set). The held (retranscode) path is behaviourally unchanged — `Some(false)` before and after — so the live-verified 4K→480p landing is unaffected. All gates re-ran on the fix commit: `make check-cargo` (lint + 18/18 unit binaries, app 1281/1281), `make check-cargo-unit-hostsim` (18/18 binaries, the plx_media hostsim 2332-test suite green, the previously failing flight test passing), `make check-nodef`, ARM cross-check. - Rebased onto `main` (includes #1297, the key-mode TLS session-resumption fix — no interaction with this change). Local note (host only, pre-existing): the python half of `make check` carries two failures on this workstation — `ci/test_build_gc.py` (16 of 58) and `ci/test_disk_preflight.py` (1 of 30). This container masks `/proc/mounts` and `/proc/1`, so `lsof` cannot enumerate open files; the `tools/disk-budget.py` liveness probe then reads `unknown` and, by design, fails closed — every fixture tree is kept as `liveness unknown (no lsof)`. Both tests fail identically on a clean checkout of `af607d8cd` (upstream `main`): the environment, not this branch; CI runners have a full `/proc`. The five codec-declaration commits and the two retranscode commits are one verified unit: the stall fix was developed and tested on the tree with the declaration fixes in place, and the live verification above ran with all seven.
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.
What broke
mainCI went red with no change on our side. Run 42562310791 passed at 04:31 UTC onubuntu-24.04; re-running the same job at 12:36 failed onubuntu-26.04, because theubuntu-latestlabel moved (runner-images#14748). Twoplx_mediatests fail deterministically in "host unit tests (default features)" and "(hostsim)", 1971 passed and 2 failed:curlio::keymode_tests::media_seeks_and_reopens_in_key_mode_each_do_their_own_handshakeatcurlio_keymode_tests.rs:174:a seek in key modecurlio::keymode_tests::media_key_mode_never_reuses_a_kept_alive_connectionat:224: the first seek after a read to EOFThe image moved libcurl 8.5.0 / OpenSSL 3.0.13 (24.04) to libcurl 8.18.0 / OpenSSL 3.5.5 (26.04), per the runner-images readmes. In both tests the first key-mode open succeeds and the first key-mode SEEK fails.
Root cause
Key mode (#378: a wrong clock fails the certificate's dates, so the server is recognised by its remembered key) confirms the key twice: libcurl enforces
CURLOPT_PINNEDPUBLICKEY, andkeypin::confirmre-reads the peer's leaf key from the certificate chain libcurl keeps forCURLOPT_CERTINFO. A handshake that RESUMES a TLS session has no certificate chain, soconfirmfinds nothing and the attempt is refused as a pin mismatch (rc 90, seek returns false).Evidence, read from the libcurl sources of both versions:
lib/vtls/openssl.c,Curl_ossl_check_peer_cert:if(data->set.ssl.certinfo && !octx->reused_session) { /* ... Reused sessions do not have cert chains */ ossl_certchain(...) }. For a reused session CERTINFO is deliberately not filled.lib/vtls/vtls_scache.c: the session cache isdata->multi->ssl_scache(or the share handle's), so every easy handle one multi runs shares it. In 8.5.0 (lib/vtls/vtls.c) it wasdata->state.session, per EASY handle.range_io::CurlSourcecreates a fresh easy handle per attempt (so before 8.12 it could never find a session) but keeps ONE multi across its attempts. From 8.12 the key-mode attempt of a seek resumes the session the previous key-mode attempt left in the multi. That is why open (first handshake, nothing cached) passes and the seek fails, and whyFRESH_CONNECT/FORBID_REUSE(connection reuse) did not help.keypin::apply, so it is fixed there for both planes.It is a real product defect and not a test problem, but not a live one on the fleet:
tools/fwcompat.pyshows no firmware in the inventory ships libcurl 8.12+, so on today's sets the session cache is per handle. It bites on the first firmware that does, and on the Linux CI runners now.Fix
keypin::applyalso setsCURLOPT_SSL_SESSIONID_CACHEto 0, besideCURLOPT_FRESH_CONNECTandCURLOPT_FORBID_REUSE: a key-mode handle neither resumes a cached TLS session nor stores one, so it always does its own full handshake and the pin and name are checked for that request. It sits in the same fail-closed list, beforeVERIFYPEERis lowered, so a libcurl that refused it would leave the handle strict.FFI/compat: an option id (LONG + 150) on the already-bound
curl_easy_setopt_long, no new symbol, noDT_NEEDED, nodynlib!change. The option exists since libcurl 7.16.0;fw-compat-reviewerconfirmed every firmware image in the database exports symbols of 7.18.0 or newer, and that both callers ofapplyfail closed on a refusal. The workflow is untouched (noruns-onchange, so nobuild-benchtable).Tests and prose:
Observed::resumed). The two red tests keep their assertions and now also assertresumed() == 0.net::key_mode_session_testsputs a shared session cache (a share handle,CURL_LOCK_DATA_SSL_SESSION, libcurl 7.23+) in front of ANY libcurl: a control proves an OpenSSL-backed libcurl does resume over it, then three key-mode transfers on fresh easy handles must each confirm the key and none may resume.plex/CLAUDE.mdand theapplydoc now name all three options and the reason.Verification, and what could not be reproduced
ubuntu-latest(26.04) is the first run of the fix on the failing library; the new key-mode test is written to fail there without the fix (round 2 resumes,confirmis false).make test-crate C=plx_net:test result: ok. 300 passed; 0 failed; 0 ignored; 0 measured; 0 filtered outmake test-crate C=plx_media:test result: ok. 1973 passed; 0 failed; 84 ignored; 0 measured; 0 filtered outmake check-nodef: finished clean. Fullmake checkis left to this PR's CI.fw-compat-reviewer: no findings (source-only; the ELF and load matrix are CI's).doc-claim-auditorandpr-reviewer: one doc inaccuracy each, fixed in the second commit.🤖 Generated with Claude Code