From 8f2da65c343a9dbd903d8f96b686bc83726614aa Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 10 Nov 2026 14:23:10 -0800 Subject: [PATCH 1/2] test(net): a refused replacement keeps a withdrawn incumbent open Regression test for the release-only unroutable race (fixed on release in fix/withdrawn-incumbent-release); main already passes it. Not yet run here. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/origin.rs | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index 81a53d8e248..18949d9d275 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -15049,6 +15049,70 @@ mod tests { assert!(matches!(next_group(&mut subscription).await, Ok(None))); } + /// The serving route is withdrawn while its copy of the track is still open, and the + /// next route for the same publisher no longer has the broadcast: its refusal must not + /// end the track, which takes the incumbent's remaining groups and clean end. + #[kio::test] + #[cfg(feature = "async")] + async fn a_refused_replacement_keeps_a_withdrawn_incumbent_open() { + // The incumbent arrives from relay 2, a stale standby from relay 3, both for + // publisher 9, so withdrawing relay 2 leaves the standby standing. + let producer = origin(1).produce(); + let server = producer + .forward( + "room", + RouteInfo::new().with_instance(instance(), 0).with_hops(hops(&[9, 2])), + ) + .unwrap(); + let standby = producer + .forward( + "room", + RouteInfo::new().with_instance(instance(), 0).with_hops(hops(&[9, 5, 3])), + ) + .unwrap(); + let pending = producer.consume().request("room/alice", None); + let upstream = broadcast::Info::new().produce(); + let old = upstream.create_track("video", crate::track::Info::timed()).unwrap(); + queued(&server).await.serve(&upstream); + let resolved = pending.await.expect("resolves"); + let mut subscription = resolved.track("video").unwrap().subscribe(None).await.unwrap(); + let mut group = old.append_group().unwrap(); + group.write_frame(crate::Timestamp::ZERO, b"before".as_ref()).unwrap(); + group.finish().unwrap(); + let mut group = next_group(&mut subscription).await.unwrap().expect("first group"); + assert_eq!(&group.read_frame().await.unwrap().unwrap().payload[..], b"before"); + + // The peer withdraws the broadcast: the route retracts and its source closes, + // while the subscription already in flight stays open. + server.withdrawn(); + upstream.close(); + + let successor = broadcast::Info::new().produce(); + let mut handler = successor.requests(); + queued(&standby).await.serve(&successor); + let request = kio::clock::timeout(Duration::from_secs(1), handler.requested_track()) + .await + .expect("the front asked the standby") + .expect("request"); + request.reject(Error::Unroutable); + for _ in 0..10 { + kio::clock::sim::yield_now().await; + } + + let mut group = old.append_group().unwrap(); + group.write_frame(crate::Timestamp::ZERO, b"last".as_ref()).unwrap(); + group.finish().unwrap(); + let mut group = next_group(&mut subscription) + .await + .expect("the incumbent keeps serving") + .expect("track open"); + assert_eq!(&group.read_frame().await.unwrap().unwrap().payload[..], b"last"); + + let _old = old.finish().unwrap(); + let end = next_group(&mut subscription).await.map(|group| group.map(|group| group.sequence)); + assert!(matches!(end, Ok(None)), "the incumbent's clean end, not {end:?}"); + } + /// The newcomer answers "video" with matching metadata, the front reads that answer, /// and only then does the newcomer abort, before its first group: still a refusal, so /// the incumbent keeps serving. From 824f30b1d39be7dd4921f22b266867b5d8ca0d47 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 10 Nov 2026 15:31:20 -0800 Subject: [PATCH 2/2] style(net): rustfmt the withdrawn-incumbent regression test Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/origin.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index d1b046f6468..e5942b20e0d 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -15083,7 +15083,9 @@ mod tests { let standby = producer .forward( "room", - RouteInfo::new().with_instance(instance(), 0).with_hops(hops(&[9, 5, 3])), + RouteInfo::new() + .with_instance(instance(), 0) + .with_hops(hops(&[9, 5, 3])), ) .unwrap(); let pending = producer.consume().request("room/alice", None); @@ -15125,7 +15127,9 @@ mod tests { assert_eq!(&group.read_frame().await.unwrap().unwrap().payload[..], b"last"); let _old = old.finish().unwrap(); - let end = next_group(&mut subscription).await.map(|group| group.map(|group| group.sequence)); + let end = next_group(&mut subscription) + .await + .map(|group| group.map(|group| group.sequence)); assert!(matches!(end, Ok(None)), "the incumbent's clean end, not {end:?}"); }