diff --git a/rs/moq-net/src/ietf/subscriber.rs b/rs/moq-net/src/ietf/subscriber.rs index 93d0c2d4d6f..6185af54433 100644 --- a/rs/moq-net/src/ietf/subscriber.rs +++ b/rs/moq-net/src/ietf/subscriber.rs @@ -1564,6 +1564,8 @@ where } let subscription = request.subscription(); + // A live join delivers nothing below the group SUBSCRIBE_OK names as Largest. + let live = subscription.as_ref().and_then(|s| s.start).is_none(); let join = match subscribe_join( subscription.as_ref().and_then(|s| s.start), subscription.as_ref().and_then(|s| s.end), @@ -1700,7 +1702,16 @@ where .with_timescale(Timescale::MICRO) .with_max_age(self.origin.default_max_age()) .with_priority(super::priority::from_wire(priority.unwrap_or(128))); + // Declared before the track is released to readers, so a warm cache waiting on + // this copy judges itself against where the live feed actually starts. + let request = match live { + true => request.resolving_start(), + false => request, + }; let mut track = request.accept(info); + if live { + let _ = track.start_at(largest.map(|largest| largest.group)); + } let mut fetching: Option> = None; { let mut state = self.state.lock(); diff --git a/rs/moq-tokio/tests/broadcast.rs b/rs/moq-tokio/tests/broadcast.rs index 4c2953a72dd..69140e2d873 100644 --- a/rs/moq-tokio/tests/broadcast.rs +++ b/rs/moq-tokio/tests/broadcast.rs @@ -995,15 +995,31 @@ async fn broadcast_route_migration() { } /// A subscriber returning to a parked track is not handed the parked cache when the -/// upstream resolves its start past it (lite-06+ resolves the start from the budget). +/// upstream resolves its start past it: lite-06+ resolves the start from the budget, and +/// an IETF live join starts at the group SUBSCRIBE_OK names as Largest. /// /// The front keeps what an unread track delivered as a warm cache. While parked, the /// publisher moved on, so the resumed upstream subscription starts well past that cache. /// The cache was only fresh against its own frozen edge; serving it first put a /// rejoining player seconds behind live. +/// +/// Pre-06 lite is skipped: nothing on those wires says where a subscription starts. #[tracing_test::traced_test] #[tokio::test] async fn broadcast_rejoin_skips_a_stale_warm_cache() { + let pre06 = [ + "moq-lite-01", + "moq-lite-02", + "moq-lite-03", + "moq-lite-04", + "moq-lite-05", + ]; + for version in moq_net::Version::names().filter(|version| !pre06.contains(version)) { + rejoin_skips_a_stale_warm_cache(version).await; + } +} + +async fn rejoin_skips_a_stale_warm_cache(version: &str) { use moq_net::Timestamp; let ms = |ms: u64| Timestamp::from_millis(ms).unwrap(); @@ -1027,6 +1043,7 @@ async fn broadcast_rejoin_skips_a_stale_warm_cache() { let mut config = moq_tokio::listen::Config::default(); config.bind = Some("[::]:0".parse().unwrap()); config.tls.generate = vec!["localhost".into()]; + config.version = vec![version.parse().unwrap()]; let mut server = config .init(Default::default()) .expect("init server") @@ -1048,6 +1065,7 @@ async fn broadcast_rejoin_skips_a_stale_warm_cache() { let mut announcements = sub_consumer.announced(); let mut config = moq_tokio::connect::Config::default(); config.tls.insecure = Some(true); + config.version = vec![version.parse().unwrap()]; let client = config.init(Default::default()).expect("init client"); let url: url::Url = format!("moqt://localhost:{}", addr.port()).parse().unwrap(); let (_client, session) = tokio::time::timeout(TIMEOUT, connect_once(client.with_subscriber(sub_origin), url)) @@ -1097,12 +1115,15 @@ async fn broadcast_rejoin_skips_a_stale_warm_cache() { let first = recv(&mut sub).await; assert!( first > 4, - "a rejoining reader was served the stale cache first: group {first}" + "{version}: a rejoining reader was served the stale cache first: group {first}" ); let mut sequence = first; while sequence < 20 { sequence = recv(&mut sub).await; - assert!(sequence >= 4, "a rejoining reader was served stale group {sequence}"); + assert!( + sequence >= 4, + "{version}: a rejoining reader was served stale group {sequence}" + ); } drop(sub);