From 9372292a60ff3dd3b2cacad5a2a1defe5f95055c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 22 Oct 2026 21:24:38 -0700 Subject: [PATCH 1/5] fix(hls): preserve denied broadcast reference errors Propagate scoped-origin Unauthorized errors through rendition reads and return uncacheable HTTP 403 without reissuing the denied binding. Preserve allowed sibling playback and missing-media behavior. Co-Authored-By: GPT-6 --- rs/moq-hls/MIGRATE.md | 9 +++ rs/moq-hls/src/export/mod.rs | 4 +- rs/moq-hls/src/export/rendition.rs | 65 ++++++++++++++--- rs/moq-hls/src/server/routes.rs | 112 ++++++++++++++++++++++++++++- 4 files changed, 176 insertions(+), 14 deletions(-) diff --git a/rs/moq-hls/MIGRATE.md b/rs/moq-hls/MIGRATE.md index 93bf229f475..de8df03d189 100644 --- a/rs/moq-hls/MIGRATE.md +++ b/rs/moq-hls/MIGRATE.md @@ -4,6 +4,15 @@ How to update your code for each breaking change, newest first. ## Unreleased +### Denied broadcast references report authorization failure + +A rendition whose referenced broadcast is outside the source origin's scope now +returns `Error::Mux(moq_mux::Error::Moq(moq_net::Error::Unauthorized))` from +playlist, init and segment reads instead of behaving like missing media. +`Broadcaster::ready` and `Rendition::playable` settle on that refusal. Embedders +should answer it with an uncacheable 403; the HTTP server does so automatically. +Allowed renditions keep serving, and missing or disconnected media remains 404. + ### HLS import unwraps fMP4 to Legacy (#6250) `import::Import` now publishes one `Legacy` frame per sample instead of one `Cmaf` frame per fragment. diff --git a/rs/moq-hls/src/export/mod.rs b/rs/moq-hls/src/export/mod.rs index 2eed7f670e4..18701b4b97d 100644 --- a/rs/moq-hls/src/export/mod.rs +++ b/rs/moq-hls/src/export/mod.rs @@ -193,8 +193,8 @@ impl Broadcaster { self.renditions.subscribe() } - /// Resolve once at least one rendition has a playable media playlist. How long to wait is - /// the caller's policy: wrap this in a timeout (or select against it) as needed. + /// Resolve once at least one rendition has a playable media playlist or a settled failure. + /// How long to wait is the caller's policy: wrap this in a timeout as needed. pub async fn ready(&self) { self.renditions.ready().await; } diff --git a/rs/moq-hls/src/export/rendition.rs b/rs/moq-hls/src/export/rendition.rs index 72b4146188f..9e3c581e5ee 100644 --- a/rs/moq-hls/src/export/rendition.rs +++ b/rs/moq-hls/src/export/rendition.rs @@ -184,6 +184,9 @@ impl Media { window.end(); } } + // A scoped origin's refusal is settled. Reissuing it cannot grant + // authority and would hide the reason the rendition cannot serve. + Poll::Ready(Err(moq_mux::Error::Moq(moq_net::Error::Unauthorized))) => {} // Only a binding that never resolved may be reissued. The source pins every // successful result, so a replacement can never answer these old rows. Poll::Ready(Err(_)) if !reissued => { @@ -201,6 +204,15 @@ impl Media { } } + /// The settled authorization refusal of this rendition's referenced broadcast. + fn refusal(&self) -> Option { + let handle = self.handle.lock().expect("media lock poisoned"); + match handle.binding.poll_broadcast(&kio::Waiter::noop()) { + Poll::Ready(Err(err @ moq_mux::Error::Moq(moq_net::Error::Unauthorized))) => Some(err.into()), + _ => None, + } + } + fn poll_track( &self, binding: &moq_mux::Binding, @@ -574,9 +586,12 @@ impl Rendition { kio::wait(|waiter| self.poll_playable(waiter)).await; } - /// Poll until this rendition has a renderable media playlist, or a timeline failed. + /// Poll until this rendition is playable, its media is denied, or a timeline failed. pub(crate) fn poll_playable(&self, waiter: &kio::Waiter) -> Poll<()> { self.poll_media(waiter); + if self.media.refusal().is_some() { + return Poll::Ready(()); + } if self.spans.poll_failed(waiter).is_ready() { return Poll::Ready(()); } @@ -598,6 +613,9 @@ impl Rendition { /// or this rendition's own timeline failed, rather than ending a truncated playlist with /// `EXT-X-ENDLIST`. A server should answer that with an uncacheable error. /// + /// A denied referenced broadcast propagates the underlying authorization error; it is + /// not missing media. The HTTP server answers it with 403 and no-store. + /// /// The playlist names its init segment by a hash of the bytes, so it is also `None` until /// the init is known. An inline-parameter-set codec (no catalog `description`) only learns /// it from media: await [`init`](Self::init) first. @@ -693,9 +711,12 @@ impl Rendition { Ok(self.snapshot_from_window(window, finished, generation)) } - /// Why every listing of `window` refuses: the reference timeline failed, or this rendition's - /// own timeline failed before covering every row it lists or will list. + /// Why listings refuse: the referenced media is denied, or a timeline failed before + /// covering every row it lists or will list. fn failure(&self, window: &segments::Window) -> Option { + if let Some(err) = self.media.refusal() { + return Some(err); + } if let Some(err) = &window.failed { return Some(err.clone()); } @@ -705,24 +726,24 @@ impl Rendition { (!failure.late || window.segments.iter().any(|row| self.is_failed(row))).then_some(failure.err) } - /// Fail if a timeline this rendition lists failed (see [`failure`](Self::failure)). + /// Refuse denied media or a failed timeline (see [`failure`](Self::failure)). fn check(&self) -> Result<()> { - if let Some(err) = self.live.failure() { + self.media.sync(&self.live); + if let Some(err) = self.media.refusal().or_else(|| self.live.failure()) { return Err(err); } // Only a failed own timeline needs the window to judge. if self.spans.failure().is_none() { return Ok(()); } - self.media.sync(&self.live); match self.failure(&self.live.window()) { Some(err) => Err(err), None => Ok(()), } } - /// Whether only this rendition's own timeline failed, so the broadcast-wide listings leave it - /// out while its siblings stay available. + /// Whether this rendition failed independently of the reference timeline, so listings + /// leave it out while its siblings stay available. pub(crate) fn failed_alone(&self) -> bool { self.live.failure().is_none() && self.check().is_err() } @@ -973,7 +994,7 @@ impl Rendition { /// [`segment`](Self::segment) serves by aligned number). #[cfg_attr(not(feature = "server"), allow(dead_code))] pub(crate) async fn segment_at(&self, tag: &str, time: u64) -> Result> { - self.media.sync(&self.live); + self.check()?; let Some(segment) = self.live.segment_number_at(tag, time, self.timescale()) else { return Ok(None); }; @@ -1083,6 +1104,7 @@ impl Rendition { } async fn load_init(&self) -> Result>> { + self.check()?; let binding = self.media.sync(&self.live); // A transmuxed segment can cache the init while another bootstrap holds `building`, // blocked on an unfinished group. @@ -1134,9 +1156,10 @@ impl Rendition { /// short groups) and encodes them as a single CMAF fragment. `None` when the segment isn't in /// the playlist window, is a gap or not yet resolved for this rendition, or its groups already /// left the relay cache. After End or Restart, only the bound instance's retained media - /// drains; a replacement's media is never read under these rows. + /// drains; a replacement's media is never read under these rows. A denied referenced + /// broadcast returns its authorization error even when the requested row is absent. pub async fn segment(&self, tag: &str, segment: u64) -> Result> { - self.media.sync(&self.live); + self.check()?; let Some(row) = self.live.row(tag, segment) else { return Ok(None); }; @@ -1145,6 +1168,7 @@ impl Rendition { /// Fetch and transmux `row`'s frames on this rendition; see [`segment`](Self::segment). pub(crate) async fn fetch(&self, row: &segments::Row) -> Result> { + self.check()?; let binding = self.media.sync(&self.live); // Read the run before resolving the row (see `restart`), so an init decoded from its // groups is never cached for a run that started while they were being fetched. @@ -1431,6 +1455,25 @@ mod tests { producer } + #[test] + fn unauthorized_binding_is_retained_without_reissuing_it() { + let origin = produce_origin(); + let broadcast = origin.create_broadcast("room/live").unwrap(); + let allowed = moq_net::Patterns::from("room/live".parse::().unwrap()); + let source = moq_mux::Source::new(origin.consume().scope("", &allowed).unwrap(), broadcast.consume()); + let mut config = VideoConfig::new(hang::catalog::VideoCodec::VP8); + config.broadcast = Some(moq_net::path::Relative::new("./secret").to_owned()); + let media = Media::bind(&source, &config, "video").unwrap(); + let window = segments::Producer::new(); + let first = media.sync(&window); + let second = media.sync(&window); + assert!(Arc::ptr_eq(&first, &second)); + assert!(matches!( + media.refusal(), + Some(crate::Error::Mux(moq_mux::Error::Moq(moq_net::Error::Unauthorized))) + )); + } + // End may land while capture's query installs a dynamically served track. The handle must // stay on that instance rather than repeat a lookup End refuses, or its retained media is lost. #[test] diff --git a/rs/moq-hls/src/server/routes.rs b/rs/moq-hls/src/server/routes.rs index 08b28075ccd..aa51a462d88 100644 --- a/rs/moq-hls/src/server/routes.rs +++ b/rs/moq-hls/src/server/routes.rs @@ -423,7 +423,12 @@ fn range_not_satisfiable() -> Response { fn server_error(err: crate::Error) -> Response { tracing::warn!(%err, "hls request failed"); - (StatusCode::INTERNAL_SERVER_ERROR, [(header::CACHE_CONTROL, "no-store")]).into_response() + let status = match err { + crate::Error::Moq(moq_net::Error::Unauthorized) + | crate::Error::Mux(moq_mux::Error::Moq(moq_net::Error::Unauthorized)) => StatusCode::FORBIDDEN, + _ => StatusCode::INTERNAL_SERVER_ERROR, + }; + (status, [(header::CACHE_CONTROL, "no-store")]).into_response() } #[cfg(test)] @@ -1113,6 +1118,111 @@ mod tests { } } + #[tokio::test(start_paused = true)] + async fn denied_sibling_media_answers_403_without_poisoning_allowed_siblings() { + let origin = moq_tokio::origin::spawn(); + let mut broadcast = origin.create_broadcast("room/live").unwrap(); + broadcast.announce(Default::default()).unwrap(); + let source = origin.create_broadcast("room/source").unwrap(); + source.announce(Default::default()).unwrap(); + let secret = origin.create_broadcast("room/secret").unwrap(); + secret.announce(Default::default()).unwrap(); + let catalog = moq_mux::catalog::Producer::new(&mut broadcast, Default::default()).unwrap(); + let reserved = catalog.reserve(); + let mut config = video_config(); + config.broadcast = Some(moq_net::path::Relative::new("./source").to_owned()); + let mut allowed = reserved + .video( + source.create_track("video0", timed()).unwrap(), + moq_mux::catalog::hang::Container::Legacy(moq_mux::container::Kind::Video), + config, + ) + .unwrap(); + let mut config = video_config(); + config.broadcast = Some(moq_net::path::Relative::new("./secret").to_owned()); + let mut denied = reserved + .video( + secret.create_track("video1", timed()).unwrap(), + moq_mux::catalog::hang::Container::Legacy(moq_mux::container::Kind::Video), + config, + ) + .unwrap(); + drop(reserved); + write_three_gops(&mut allowed); + write_three_gops(&mut denied); + + let patterns = ["room/live", "room/source"] + .into_iter() + .map(|path| path.parse::().unwrap()) + .collect(); + let restricted = origin.consume().scope("", &patterns).unwrap(); + let server = Server::new(restricted, Default::default()); + let broadcaster = server.broadcaster("room/live").await.unwrap(); + broadcaster.ready().await; + let allowed_uri = "/room/live/video/video0/seg/656e3d1b.0.m4s"; + let denied_uri = "/room/live/video/video1/seg/656e3d1b.0.m4s"; + let app = server.router(); + assert_eq!(oneshot(app.clone(), allowed_uri).await.status(), StatusCode::OK); + for uri in [ + denied_uri, + "/room/live/video/video1/media.m3u8", + "/room/live/video/video1/init.unknown.mp4", + ] { + let response = oneshot(app.clone(), uri).await; + assert_eq!(response.status(), StatusCode::FORBIDDEN, "{uri}"); + assert_eq!(response.headers()[header::CACHE_CONTROL], "no-store"); + assert!( + axum::body::to_bytes(response.into_body(), usize::MAX) + .await + .unwrap() + .is_empty() + ); + } + let master = oneshot(app.clone(), "/room/live/master.m3u8").await; + assert_eq!(master.status(), StatusCode::OK); + let master = axum::body::to_bytes(master.into_body(), usize::MAX).await.unwrap(); + let master = String::from_utf8(master.to_vec()).unwrap(); + assert!(master.contains("video/video0/")); + assert!(!master.contains("video/video1/")); + let rendition = broadcaster.rendition(Kind::Video, "video1").unwrap(); + assert!(matches!( + rendition.segment("656e3d1b", 0).await, + Err(crate::Error::Mux(moq_mux::Error::Moq(moq_net::Error::Unauthorized))) + )); + // Broader authority can consume the referenced bytes, but cannot warm the + // restricted server's export into using them. + let broad = moq_mux::Source::new(origin.consume(), broadcast.consume()); + let referenced = broad + .resolve(Some(&moq_net::path::Relative::new("./secret")), None) + .await + .unwrap(); + let mut group = referenced.track("video1").unwrap().fetch_group(0, None).await.unwrap(); + assert!(group.read_frame().await.unwrap().is_some()); + assert_eq!(oneshot(app.clone(), denied_uri).await.status(), StatusCode::FORBIDDEN); + assert_eq!(oneshot(app.clone(), allowed_uri).await.status(), StatusCode::OK); + assert_eq!( + oneshot(app, "/room/live/video/video0/seg/656e3d1b.9999.m4s") + .await + .status(), + StatusCode::NOT_FOUND + ); + // Readiness settles even when no rendition is authorized; it must not need + // an allowed sibling to wake the server into reporting the typed refusal. + let only_catalog = origin + .consume() + .scope( + "", + &moq_net::Patterns::from("room/live".parse::().unwrap()), + ) + .unwrap(); + let all_denied = Server::new(only_catalog, Default::default()); + all_denied.broadcaster("room/live").await.unwrap().ready().await; + assert_eq!( + oneshot(all_denied.router(), denied_uri).await.status(), + StatusCode::FORBIDDEN + ); + } + #[tokio::test] async fn a_disconnected_sibling_publisher_answers_404() { let pair = lite_pair().await; From 8c6d076efb62c09305999a3879fccad833c865f3 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 22 Oct 2026 21:33:25 -0700 Subject: [PATCH 2/5] fix(hls): keep retained media independent of timeline failures Use the private authorization guard for media reads while preserving timeline failure checks for listings. Cover retained init and segment draining alongside denied references. Co-Authored-By: GPT-6 --- rs/moq-hls/src/export/rendition.rs | 23 +++++++++++++++-------- rs/moq-hls/src/server/routes.rs | 8 ++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/rs/moq-hls/src/export/rendition.rs b/rs/moq-hls/src/export/rendition.rs index 9e3c581e5ee..c067ecb21d3 100644 --- a/rs/moq-hls/src/export/rendition.rs +++ b/rs/moq-hls/src/export/rendition.rs @@ -726,10 +726,19 @@ impl Rendition { (!failure.late || window.segments.iter().any(|row| self.is_failed(row))).then_some(failure.err) } + /// Return bound media or its authorization refusal, leaving timeline state alone. + fn authorize(&self) -> Result> { + let binding = self.media.sync(&self.live); + match self.media.refusal() { + Some(err) => Err(err), + None => Ok(binding), + } + } + /// Refuse denied media or a failed timeline (see [`failure`](Self::failure)). fn check(&self) -> Result<()> { - self.media.sync(&self.live); - if let Some(err) = self.media.refusal().or_else(|| self.live.failure()) { + self.authorize()?; + if let Some(err) = self.live.failure() { return Err(err); } // Only a failed own timeline needs the window to judge. @@ -994,7 +1003,7 @@ impl Rendition { /// [`segment`](Self::segment) serves by aligned number). #[cfg_attr(not(feature = "server"), allow(dead_code))] pub(crate) async fn segment_at(&self, tag: &str, time: u64) -> Result> { - self.check()?; + self.authorize()?; let Some(segment) = self.live.segment_number_at(tag, time, self.timescale()) else { return Ok(None); }; @@ -1104,8 +1113,7 @@ impl Rendition { } async fn load_init(&self) -> Result>> { - self.check()?; - let binding = self.media.sync(&self.live); + let binding = self.authorize()?; // A transmuxed segment can cache the init while another bootstrap holds `building`, // blocked on an unfinished group. if let Some(init) = self.run().init { @@ -1159,7 +1167,7 @@ impl Rendition { /// drains; a replacement's media is never read under these rows. A denied referenced /// broadcast returns its authorization error even when the requested row is absent. pub async fn segment(&self, tag: &str, segment: u64) -> Result> { - self.check()?; + self.authorize()?; let Some(row) = self.live.row(tag, segment) else { return Ok(None); }; @@ -1168,8 +1176,7 @@ impl Rendition { /// Fetch and transmux `row`'s frames on this rendition; see [`segment`](Self::segment). pub(crate) async fn fetch(&self, row: &segments::Row) -> Result> { - self.check()?; - let binding = self.media.sync(&self.live); + let binding = self.authorize()?; // Read the run before resolving the row (see `restart`), so an init decoded from its // groups is never cached for a run that started while they were being fetched. let run = self.run(); diff --git a/rs/moq-hls/src/server/routes.rs b/rs/moq-hls/src/server/routes.rs index aa51a462d88..9475f7a389f 100644 --- a/rs/moq-hls/src/server/routes.rs +++ b/rs/moq-hls/src/server/routes.rs @@ -1221,6 +1221,14 @@ mod tests { oneshot(all_denied.router(), denied_uri).await.status(), StatusCode::FORBIDDEN ); + + // A timeline failure refuses listings, but its already-retained media + // still drains. Authorization checks must not broaden that failure. + let retained = broadcaster.rendition(Kind::Video, "video0").unwrap(); + retained.fail(crate::Error::Moq(moq_net::Error::SessionClosed)); + assert!(retained.media_playlist(None).is_err()); + assert!(retained.init().await.unwrap().is_some()); + assert!(retained.segment("656e3d1b", 0).await.unwrap().is_some()); } #[tokio::test] From 32f87b34393dace0b2b0b16b3a1a07f53ae949dc Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 22 Oct 2026 21:57:37 -0700 Subject: [PATCH 3/5] fix(hls): propagate authorization refused during media reads Co-Authored-By: GPT-6 --- rs/moq-hls/src/export/rendition.rs | 53 +++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/rs/moq-hls/src/export/rendition.rs b/rs/moq-hls/src/export/rendition.rs index c067ecb21d3..7ffd65d7168 100644 --- a/rs/moq-hls/src/export/rendition.rs +++ b/rs/moq-hls/src/export/rendition.rs @@ -1062,8 +1062,17 @@ impl Rendition { async fn track( &self, binding: &moq_mux::Binding, - ) -> Option<(moq_net::broadcast::Consumer, moq_net::track::Consumer)> { - kio::wait(|waiter| self.media.poll_track(binding, waiter)).await + ) -> Result> { + let track = kio::wait(|waiter| self.media.poll_track(binding, waiter)).await; + // The bind can be refused while this read waits. Preserve that exact instance's + // authorization error; other failed or disconnected references stay missing. + if track.is_none() + && let Poll::Ready(Err(err @ moq_mux::Error::Moq(moq_net::Error::Unauthorized))) = + binding.poll_broadcast(&kio::Waiter::noop()) + { + return Err(err.into()); + } + Ok(track) } /// The media track's name in its broadcast, which can differ from the rendition's ID. @@ -1137,7 +1146,7 @@ impl Rendition { let Some(sequence) = latest.or_else(|| self.live.latest_keyframe_group(&reference)) else { return Ok(None); }; - let Some((broadcast, track)) = self.track(&binding).await else { + let Some((broadcast, track)) = self.track(&binding).await? else { return Ok(None); }; let Ok(mut group) = fetch(&track, hang::timeline::Position::group(sequence), None, &broadcast).await? @@ -1199,7 +1208,7 @@ impl Rendition { return Ok(None); } - let Some((broadcast, track)) = self.track(&binding).await else { + let Some((broadcast, track)) = self.track(&binding).await? else { return Ok(None); }; @@ -1481,6 +1490,42 @@ mod tests { )); } + #[tokio::test] + async fn a_pending_segment_preserves_a_later_authorization_refusal() { + let origin = moq_tokio::origin::spawn(); + let broadcast = origin.create_broadcast("room/live").unwrap(); + let dynamic = origin.dynamic_route("room/secret", Default::default()).unwrap(); + let source = moq_mux::Source::new(origin.consume(), broadcast.consume()); + let mut config = VideoConfig::new(hang::catalog::VideoCodec::VP8); + config.broadcast = Some(moq_net::path::Relative::new("./secret").to_owned()); + let rendition = Rendition::video("video".into(), &config, &source, Archive::default(), None).unwrap(); + let request = dynamic.requested_broadcast().await.unwrap(); + let row = segments::Row { + index: 0, + segment: 0, + period: moq_net::Timestamp::ZERO, + reference: Arc::new((Kind::Video, "video".into(), "video".into())), + frames: hang::timeline::Position::group(0)..hang::timeline::Position::group(1), + keyframe: true, + duration: Duration::from_secs(1), + pts: moq_net::Timestamp::ZERO, + end: Duration::from_secs(1), + discontinuity: 0, + }; + let segment = rendition.fetch(&row); + tokio::pin!(segment); + tokio::select! { + biased; + _ = &mut segment => panic!("the reference request has not been answered"), + _ = std::future::ready(()) => {} + } + request.reject(moq_net::Error::Unauthorized); + assert!(matches!( + segment.await, + Err(crate::Error::Mux(moq_mux::Error::Moq(moq_net::Error::Unauthorized))) + )); + } + // End may land while capture's query installs a dynamically served track. The handle must // stay on that instance rather than repeat a lookup End refuses, or its retained media is lost. #[test] From 645e8387cd5031d19fd4dbd24826f403fbc4f919 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 23 Oct 2026 19:37:44 -0700 Subject: [PATCH 4/5] fix(hls): fail the segment cursor on a denied reference A cursor over a denied rendition waited forever on its empty window. It now fails with the authorization error, including a refusal that lands while it waits. Co-Authored-By: Claude Opus 5.5 --- rs/moq-hls/src/export/rendition.rs | 15 ++++++++++++--- rs/moq-hls/src/export/segments.rs | 8 +++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/rs/moq-hls/src/export/rendition.rs b/rs/moq-hls/src/export/rendition.rs index 0e13385b924..cf601cecc42 100644 --- a/rs/moq-hls/src/export/rendition.rs +++ b/rs/moq-hls/src/export/rendition.rs @@ -702,7 +702,7 @@ impl Rendition { } /// Return bound media or its authorization refusal, leaving timeline state alone. - fn authorize(&self) -> Result> { + pub(crate) fn authorize(&self) -> Result> { let binding = self.media.sync(&self.live); match self.media.refusal() { Some(err) => Err(err), @@ -1453,14 +1453,14 @@ mod tests { } #[tokio::test] - async fn a_pending_segment_preserves_a_later_authorization_refusal() { + async fn pending_reads_preserve_a_later_authorization_refusal() { let origin = moq_tokio::origin::spawn(); let broadcast = origin.create_broadcast("room/live").unwrap(); let dynamic = origin.dynamic_route("room/secret", Default::default()).unwrap(); let source = moq_mux::Source::new(origin.consume(), broadcast.consume()); let mut config = VideoConfig::new(hang::catalog::VideoCodec::VP8); config.broadcast = Some(moq_net::path::Relative::new("./secret").to_owned()); - let rendition = Rendition::video("video".into(), &config, &source, Archive::default(), None).unwrap(); + let rendition = Arc::new(Rendition::video("video".into(), &config, &source, Archive::default(), None).unwrap()); let request = dynamic.requested_broadcast().await.unwrap(); let row = segments::Row { index: 0, @@ -1476,9 +1476,14 @@ mod tests { }; let segment = rendition.fetch(&row); tokio::pin!(segment); + // The cursor waits on a window with no rows, which the refusal neither fills nor ends. + let mut cursor = rendition.segments(); + let next = cursor.next(); + tokio::pin!(next); tokio::select! { biased; _ = &mut segment => panic!("the reference request has not been answered"), + _ = &mut next => panic!("the reference request has not been answered"), _ = std::future::ready(()) => {} } request.reject(moq_net::Error::Unauthorized); @@ -1486,6 +1491,10 @@ mod tests { segment.await, Err(crate::Error::Mux(moq_mux::Error::Moq(moq_net::Error::Unauthorized))) )); + assert!(matches!( + next.await, + Err(crate::Error::Mux(moq_mux::Error::Moq(moq_net::Error::Unauthorized))) + )); } // End may land while capture's query installs a dynamically served track. The handle must diff --git a/rs/moq-hls/src/export/segments.rs b/rs/moq-hls/src/export/segments.rs index cd6dd3ec744..9ba52c7eb5a 100644 --- a/rs/moq-hls/src/export/segments.rs +++ b/rs/moq-hls/src/export/segments.rs @@ -529,7 +529,8 @@ impl Consumer { /// /// Once a timeline fails (the reference's, or this rendition's own), the cursor drains the /// segments it still covers, then fails every call with - /// [`TimelineFailed`](crate::Error::TimelineFailed), as [`Rendition::playlist`] does. + /// [`TimelineFailed`](crate::Error::TimelineFailed), as [`Rendition::playlist`] does. A + /// denied referenced broadcast fails every call with its authorization error. /// /// Waits for the next segment to resolve on this rendition, then FETCHes and transmuxes its /// frames. A segment whose groups already left the relay cache (or that is a gap for this @@ -565,6 +566,11 @@ impl Consumer { fn poll_next(&mut self, waiter: &kio::Waiter) -> Poll>> { self.poll_feed(waiter); + // A refused binding never held media, so there is nothing to drain. `poll_feed` registered + // the wake for a refusal that arrives while the window waits for rows. + if let Err(err) = self.rendition.authorize() { + return Poll::Ready(Err(err)); + } let poll = self .state .poll(waiter, |state| match state.next_after(self.after.as_ref()) { From d4b87d8ad13f44eda73970fcc601e496b2d389c3 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 23 Oct 2026 19:52:37 -0700 Subject: [PATCH 5/5] fix(hls): observe a denied reference while the cursor resolves a row Co-Authored-By: Claude Opus 5.5 --- rs/moq-hls/src/export/rendition.rs | 35 +++++++++++++++++++++--------- rs/moq-hls/src/export/segments.rs | 8 ++++++- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/rs/moq-hls/src/export/rendition.rs b/rs/moq-hls/src/export/rendition.rs index cf601cecc42..e4ac4912411 100644 --- a/rs/moq-hls/src/export/rendition.rs +++ b/rs/moq-hls/src/export/rendition.rs @@ -1462,11 +1462,15 @@ mod tests { config.broadcast = Some(moq_net::path::Relative::new("./secret").to_owned()); let rendition = Arc::new(Rendition::video("video".into(), &config, &source, Archive::default(), None).unwrap()); let request = dynamic.requested_broadcast().await.unwrap(); - let row = segments::Row { + let other = origin.dynamic_route("room/hidden", Default::default()).unwrap(); + config.broadcast = Some(moq_net::path::Relative::new("./hidden").to_owned()); + let resolving = Arc::new(Rendition::video("video".into(), &config, &source, Archive::default(), None).unwrap()); + let other_request = other.requested_broadcast().await.unwrap(); + let row = |reference: &str| segments::Row { index: 0, segment: 0, period: moq_net::Timestamp::ZERO, - reference: Arc::new((Kind::Video, "video".into(), "video".into())), + reference: Arc::new((Kind::Video, reference.into(), reference.into())), frames: hang::timeline::Position::group(0)..hang::timeline::Position::group(1), keyframe: true, duration: Duration::from_secs(1), @@ -1474,27 +1478,38 @@ mod tests { end: Duration::from_secs(1), discontinuity: 0, }; - let segment = rendition.fetch(&row); + let own = row("video"); + let segment = rendition.fetch(&own); tokio::pin!(segment); // The cursor waits on a window with no rows, which the refusal neither fills nor ends. let mut cursor = rendition.segments(); let next = cursor.next(); tokio::pin!(next); + // This cursor waits for its own timeline to resolve another rendition's row, which the + // refusal never does either. + resolving.live.push(row("other"), None); + let mut resolving_cursor = resolving.segments(); + let resolving_next = resolving_cursor.next(); + tokio::pin!(resolving_next); tokio::select! { biased; _ = &mut segment => panic!("the reference request has not been answered"), _ = &mut next => panic!("the reference request has not been answered"), + _ = &mut resolving_next => panic!("the reference request has not been answered"), _ = std::future::ready(()) => {} } request.reject(moq_net::Error::Unauthorized); - assert!(matches!( + other_request.reject(moq_net::Error::Unauthorized); + for read in [ segment.await, - Err(crate::Error::Mux(moq_mux::Error::Moq(moq_net::Error::Unauthorized))) - )); - assert!(matches!( - next.await, - Err(crate::Error::Mux(moq_mux::Error::Moq(moq_net::Error::Unauthorized))) - )); + next.await.map(|_| None), + resolving_next.await.map(|_| None), + ] { + assert!(matches!( + read, + Err(crate::Error::Mux(moq_mux::Error::Moq(moq_net::Error::Unauthorized))) + )); + } } // End may land while capture's query installs a dynamically served track. The handle must diff --git a/rs/moq-hls/src/export/segments.rs b/rs/moq-hls/src/export/segments.rs index 9ba52c7eb5a..451edd2cb22 100644 --- a/rs/moq-hls/src/export/segments.rs +++ b/rs/moq-hls/src/export/segments.rs @@ -543,7 +543,13 @@ impl Consumer { let Some((row, resets)) = kio::wait(|waiter| self.poll_next(waiter)).await? else { return Ok(None); }; - kio::wait(|waiter| self.rendition.poll_resolved(waiter, &row)).await; + kio::wait(|waiter| { + // The refusal settles the binding, not this rendition's timeline, so watch both. + self.rendition.poll_media(waiter); + self.rendition.authorize()?; + self.rendition.poll_resolved(waiter, &row).map(Ok::<_, crate::Error>) + }) + .await?; // This rendition's timeline failed before covering the row, so no later row resolves. if let Some(err) = self.rendition.own_failure() && self.rendition.is_failed(&row)