diff --git a/quest/m1/resume-owed-wake.md b/quest/m1/resume-owed-wake.md deleted file mode 100644 index 604c8b45a5..0000000000 --- a/quest/m1/resume-owed-wake.md +++ /dev/null @@ -1,23 +0,0 @@ -# [S] A key-order read holding a copy's cursor wakes when the owed group lands - -## Goal - -A key-order read on a front's logical track that leaves a copy's cursor below a group -outside its window, because the window still owes a group under it -(`Reader::poll_lowest`, the `owes_below` break in `rs/moq-net/src/model/resume.rs`), -wakes when that owed group lands on the copy. - -## Plan - -Found by [moq-dev/moq#9144](https://github.com/moq-dev/moq/pull/9144) while killing the -`owes_below` mutants: in `a_key_order_read_waits_below_a_group_outside_its_window_only_while_one_is_owed`, -a read polled with a real waiter after the break stays unwoken when group 0 lands on copy -b. The copy's peek returned the reserved group, so nothing registered a wake for a lower -key landing, and the read's idle shortcut then answers `Pending` until something else -fires (another copy's group, a route change, a deadline). With the replaced copy dead it -stalls until the budget runs out. - -Reproduce it with that setup and a `Wake` waiter, then register the copy's arrivals -(`track.poll_arrived`, as the drained arm does) before the break, and assert the wake. - -Public API: none. Wire: none. diff --git a/rs/moq-net/src/model/resume.rs b/rs/moq-net/src/model/resume.rs index dd06a43931..013b8bb34d 100644 --- a/rs/moq-net/src/model/resume.rs +++ b/rs/moq-net/src/model/resume.rs @@ -1800,7 +1800,14 @@ impl Reader { if !deliverable || !self.window().contains(key) { // Skipping an ordered cursor past a group the window still owes below // would lose it, though it may yet land on this copy: leave it there. + // The peek returned the held group, so only the copy's arrivals wake + // the read when the owed one lands: one already landed is peeked again. if ordered && deliverable && self.owes_below(floor, key, delivered) { + let copy = &self.copies[index]; + if copy.track.poll_arrived(arrivals, waiter).is_ready() { + arrivals = copy.track.arrived(); + continue; + } break; } let Sub::Ready(sub) = &mut self.copies[index].sub else { @@ -6016,6 +6023,50 @@ mod test { assert_eq!(drain(&mut sub, true), [0, 10, 11]); } + /// A key-order read holding a copy's cursor on a group outside its window, for a group the + /// window still owes below it, wakes when that group lands on the copy. + #[test] + #[cfg(feature = "async")] + fn a_key_order_read_holding_a_copy_wakes_when_the_owed_group_lands() { + let routes = Producer::new(); + let logical = logical(&routes); + let a = received_copy(); + write(&a, 10); + routes.serve(a.consume()); + let from_ten = track::Range { + start: track::Anchor::Time(10), + end: None, + }; + let subscription = Subscription::default() + .with_delay(Delay::default().with_max(HOUR)) + .with_ranges([track::Range::groups(0..1), from_ten]); + let mut sub = logical + .consume() + .subscribe(subscription) + .now_or_never() + .unwrap() + .unwrap(); + // a places the window at 0 and from 10; the cap holds 10 back. + sub.set_range(..10); + assert!(drain(&mut sub, true).is_empty()); + + // b holds 5 but not 10, so it places the second range at 5, and 0 is owed below it. + let b = received_copy(); + write(&b, 5); + routes.serve(b.consume()); + let wake = Arc::new(Wake::default()); + let waiter = kio::Waiter::new(wake.clone().into()); + assert!(sub.poll_next_group(&waiter).is_pending()); + wake.0.store(false, std::sync::atomic::Ordering::Relaxed); + write(&b, 0); + assert!(wake.0.load(std::sync::atomic::Ordering::Relaxed)); + // The same task's read hands it out, not the idle answer it parked with. + let Poll::Ready(Ok(Some(group))) = sub.poll_next_group(&waiter) else { + panic!("the owed group is handed out") + }; + assert_eq!(group.start, 0); + } + #[test] fn ordered_replay_skips_unbounded_copies_while_a_nested_route_waits() { for nested in [false, true] {