From 84bcacc592d0922171738b0a800bed14cfe9313a Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 15 Oct 2026 10:27:43 -0700 Subject: [PATCH 1/2] chore: claim FETCH edge-case release backport Co-Authored-By: GPT-6 From cb71cd050c2c6634628d606f2db7e6c0553177d5 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 15 Oct 2026 11:09:21 -0700 Subject: [PATCH 2/2] fix(net): backport FETCH end-location correctness Co-Authored-By: GPT-6 --- rs/moq-net/src/ietf/publisher.rs | 45 ++++++++--- rs/moq-net/src/ietf/subscriber.rs | 129 +++++++++++++++++------------- 2 files changed, 111 insertions(+), 63 deletions(-) diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index 599781d077f..d81abc60a9f 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -1,5 +1,6 @@ use crate::runtime::Timers as _; use crate::{frame, group, origin, track}; +use futures::FutureExt as _; use std::{ collections::HashMap, ops::Bound, @@ -60,7 +61,7 @@ struct FetchedGroup { /// The Object ID of the first frame. first: u64, frames: Vec, - /// The group ended within the range, so every frame it will ever hold was read. + /// The fetched range reached the finished group's final object. complete: bool, } @@ -102,16 +103,16 @@ async fn read_fetch( // longer holds it. let first = group.index(); let mut frames = Vec::new(); - let mut complete = false; while until.is_none_or(|until| first + (frames.len() as u64) < until) { - match group.read_frame().await? { - Some(frame) => frames.push(frame), - None => { - complete = true; - break; - } - } + let Some(frame) = group.read_frame().await? else { + break; + }; + frames.push(frame); } + // A bounded range can reach the group's end without reading its terminal None, and a + // start past the end is already there. + let complete = + matches!(group.finished().now_or_never(), Some(Ok(_))) && group.index() >= group.frame_count() as u64; Ok(FetchedGroup { sequence, @@ -4554,6 +4555,32 @@ mod serve_tests { } } + /// A bounded range ending at the last object still reports the track's end; a + /// shorter prefix must not claim that the track ends there. + #[tokio::test(start_paused = true)] + async fn a_fetch_ending_at_the_final_object_reports_the_end_of_track() { + for version in FETCH_DRAFTS { + for end in [1, 2] { + let mut h = serve(version); + publish_pairs(&mut h, 5, None); + h.track.finish().unwrap(); + settle().await; + + let buf = standalone_fetch( + &h, + Location { group: 4, object: 0 }, + Location { group: 4, object: end }, + GroupOrder::Ascending, + ) + .await; + let (ok, objects) = fetch_answer(buf, version); + assert_eq!(ok.end_location, end_location(version, 4, end - 1), "{version}"); + assert_eq!(ok.end_of_track, end == 2, "{version}: exclusive end {end}"); + assert_eq!(objects, pairs([4])[..end as usize].to_vec(), "{version}"); + } + } + } + /// A draft-20 filter bounded by Largest Object is refused, even when that bound would /// land in the start group: the one-group rule needs it resolved first. #[tokio::test(start_paused = true)] diff --git a/rs/moq-net/src/ietf/subscriber.rs b/rs/moq-net/src/ietf/subscriber.rs index ccef616f82f..8fe0ccc348d 100644 --- a/rs/moq-net/src/ietf/subscriber.rs +++ b/rs/moq-net/src/ietf/subscriber.rs @@ -3094,11 +3094,15 @@ where end.object = object; } - // From draft-20 an empty answer still covers its start, so an End Location before it - // is malformed and closes the session (section 10.14), before it can mark the track's end. - if draft20 && (end.group, end.object) <= (sequence, start) { + // Draft-20's answer must cover its start within the requested group. Validate before + // accepting the group or letting End of Track mark where the track ends. + if draft20 && (end.group != sequence || end.object <= start) { let err = Error::ProtocolViolation; - tracing::warn!(group = sequence, ?end, "FETCH_OK's End Location is before its start"); + tracing::warn!( + group = sequence, + ?end, + "FETCH_OK's End Location is outside the requested range" + ); self.session .clone() .close(SessionError::from(&err).to_code(), err.to_string().as_ref()); @@ -7932,67 +7936,84 @@ mod joining_fetch_tests { assert!(fetch.await.is_err(), "the accepted group was aborted"); } - /// From draft-20 an End Location before the FETCH's start is malformed (section 10.14): + /// From draft-20 an End Location outside the FETCH's range is malformed: /// the session closes with PROTOCOL_VIOLATION rather than reading it as an empty answer. #[tokio::test(start_paused = true)] - async fn a_draft20_end_location_before_the_start_closes_the_session() { - const VERSION: Version = Version::Draft20; + async fn a_draft20_end_location_outside_the_range_closes_the_session() { const GROUP: u64 = 4; const START: u64 = 3; - let ok = message_bytes( - ietf::FetchOk::ID, - &ietf::FetchOk { - request_id: None, - group_order: GroupOrder::Ascending, - end_of_track: false, - end_location: ietf::Location { + for version in [Version::Draft20, Version::Draft21, Version::Draft22] { + for end_location in [ + ietf::Location { group: GROUP, object: START - 1, }, - }, - VERSION, - ); - - let session = ScriptedSession::per_stream_eof(vec![ok]); - let (tasks, _task_set) = crate::util::TaskSet::new(); - let subscriber = Subscriber::new( - crate::time::Clock::tokio(), - session.clone(), - crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce(), - Control::new(None, false), - None, - peer::PeerSetup::default(), - crate::Hop::new(1).unwrap(), - None, - VERSION, - tasks, - Default::default(), - ); + ietf::Location { + group: GROUP + 1, + object: 0, + }, + ] { + for end_of_track in [false, true] { + let ok = message_bytes( + ietf::FetchOk::ID, + &ietf::FetchOk { + request_id: None, + group_order: GroupOrder::Ascending, + end_of_track, + end_location, + }, + version, + ); - let track = track::Producer::new( - std::sync::Arc::new(crate::broadcast::Info::default()), - "video", - track::Info::default(), - ); - let dynamic = track.dynamic(); - let consumer = track.consume(); - let mut fetch = std::pin::pin!(consumer.fetch_group(GROUP, group::Fetch::default().with_frame_start(START))); - assert!(futures::poll!(fetch.as_mut()).is_pending()); - let request = dynamic.requested_group().await.expect("no group requested"); + let session = ScriptedSession::per_stream_reset(vec![ok]); + let (tasks, _task_set) = crate::util::TaskSet::new(); + let subscriber = Subscriber::new( + crate::time::Clock::tokio(), + session.clone(), + crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce(), + Control::new(None, false), + None, + peer::PeerSetup::default(), + crate::Hop::new(1).unwrap(), + None, + version, + tasks, + Default::default(), + ); - subscriber - .clone() - .run_group_fetch(Path::new("broadcast").to_owned(), "video".into(), request, None) - .await; + let track = track::Producer::new( + std::sync::Arc::new(crate::broadcast::Info::default()), + "video", + track::Info::default(), + ); + let dynamic = track.dynamic(); + let consumer = track.consume(); + let mut fetch = + std::pin::pin!(consumer.fetch_group(GROUP, group::Fetch::default().with_frame_start(START))); + assert!(futures::poll!(fetch.as_mut()).is_pending()); + let request = dynamic.requested_group().await.expect("no group requested"); + + subscriber + .clone() + .run_group_fetch(Path::new("broadcast").to_owned(), "video".into(), request, None) + .await; - assert!(matches!(fetch.await, Err(Error::ProtocolViolation))); - let violation = SessionError::from(&Error::ProtocolViolation).to_code(); - assert!( - session.log.closes().iter().any(|(code, _)| *code == violation), - "{:?}", - session.log.closes() - ); + assert_eq!( + consumer.final_sequence(), + None, + "{version}: rejected end changed the track" + ); + assert!(matches!(fetch.await, Err(Error::ProtocolViolation))); + let violation = SessionError::from(&Error::ProtocolViolation).to_code(); + assert!( + session.log.closes().iter().any(|(code, _)| *code == violation), + "{:?}", + session.log.closes() + ); + } + } + } } /// A cache miss for a group's tail asks upstream from the frame the reader wants and