Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions js/net/src/lite/fills.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,14 @@ test("range fills: a stale drop of asked groups is recovered once, on a subscrip
fills.refuse(1n, 3n, new StreamError(StreamCode.Old));
fills.poll(tail, true);
expect(opened.map((entry) => entry.groups)).toEqual([{ start: 1n, end: 3n }]);
// With the fill's priority. The run already asked stays asked whole while the fill owes any of
// it, so the subscription does not change under the recovery.
// With the fill's priority. The recovered run leaves the subscription, though the rest of the
// fill's run stays asked: left in, any later update would reopen its stale drop there, and the
// publisher would serve it on both.
expect(opened[0]?.priority).toBe(peer.fill.priority);
expect(fills.ask.groups).toEqual([{ start: 0n, end: 4n }]);
expect(fills.ask.groups).toEqual([
{ start: 0n, end: 1n },
{ start: 3n, end: 4n },
]);

// The recovery delivered nothing, and the next stale drop of the same groups stands.
opened[0]?.finish([]);
Expand Down
7 changes: 5 additions & 2 deletions js/net/src/lite/fills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,12 @@ export class RangeFills {
for (const sequence of this.#reading.keys())
if (!draining.some((run) => run.start <= sequence && sequence < run.end)) this.#reading.delete(sequence);
this.#draining = draining;
// A run being recovered leaves the subscription, even out of a run kept whole: any later update
// reopens its stale drop there, and the publisher would serve it on both.
const remaining = this.#recovering.reduce((runs, run) => removeRun(runs, run.start, run.end), groups);
// What finishes a stream still asks with what its fills asked.
if (this.#held.length === 0 && groups.length > 0) ask.priority = this.ask.priority;
ask.groups = groups;
if (this.#held.length === 0 && remaining.length > 0) ask.priority = this.ask.priority;
ask.groups = remaining;
if (ask.priority === this.ask.priority && sameRuns(ask.groups, this.ask.groups))
return this.isEmpty() !== empty;
this.#retireSkipped(ask.groups);
Expand Down
30 changes: 0 additions & 30 deletions quest/m2/subscribe-ranges/recovery-duplicate.md

This file was deleted.

53 changes: 53 additions & 0 deletions rs/moq-net/src/lite/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6387,6 +6387,59 @@ mod tests {
(serve, serving, tail, broadcast)
}

/// A stale drop of part of a fill's run recovers that part on its own subscription, which
/// takes it out of the copy's ranges at once, though the rest of the run stays asked: left
/// in, any later update would reopen the stale drop and the publisher would serve the
/// recovered groups on both.
#[kio::test]
#[expect(clippy::single_range_in_vec_init, reason = "the asked runs are a list, here one")]
async fn a_recovered_run_leaves_the_subscription() {
let (serve, _serving, _tail, _broadcast) = lite07_serving(Duration::from_millis(500)).await;
let waiter = kio::Waiter::noop();
let copy = crate::track::Producer::new(
std::sync::Arc::new(crate::broadcast::Info::default()),
"video",
crate::track::Info::default()
.with_timescale(crate::Timescale::MILLI)
.with_max_age(None),
);
let requests = copy.requests();
for sequence in 0..6 {
let mut group = copy.create_group(group::Info { sequence }).unwrap();
group
.write_frame(crate::Timestamp::from_millis(sequence * 1000).unwrap(), b"x".as_slice())
.unwrap();
group.finish().unwrap();
}
for sequence in 1..5 {
copy.evict(sequence);
}
let mut reader = copy
.subscribe(
crate::track::Subscription::default()
.with_delay(crate::track::Delay::default().with_max(None))
.with_range(1..5),
)
.ordered();
assert!(reader.poll_next_group(&waiter).is_pending(), "groups 1..5 are owed");
let Poll::Ready(Ok(fill)) = requests.poll_requested_fill(&waiter) else {
panic!("groups 1..5 are a miss");
};
let mut fills = fills::RangeFills::default();
fills.push(fill);
assert!(fills.poll(&serve, &copy, None, true, &waiter).unwrap());
assert_eq!(fills.ask.groups.iter().cloned().collect::<Vec<_>>(), [1..5]);

fills.refuse(1..3, crate::StreamError::Old);
assert!(fills.poll(&serve, &copy, None, true, &waiter).unwrap());
assert!(fills.recovering(), "1..3 recovered on its own subscription");
assert_eq!(
fills.ask.groups.iter().cloned().collect::<Vec<_>>(),
[3..5],
"the recovered run is no longer asked"
);
}

/// A SUBSCRIBE_DROP can only echo an update the subscriber sent: one naming a later update
/// is a protocol violation, and accounts for nothing.
#[kio::test]
Expand Down
5 changes: 5 additions & 0 deletions rs/moq-net/src/lite/subscriber/fills.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@ impl RangeFills {
}
self.reading.retain(|sequence, _| draining.contains(sequence));
self.draining = draining;
// A run being recovered leaves the subscription, even out of a run kept whole: any later
// update reopens its stale drop there, and the publisher would serve it on both.
for run in self.recovering.iter() {
groups.remove(run.clone());
}
// What finishes a stream still asks with what its fills asked.
if self.held.is_empty() && !groups.is_empty() {
ask.priority = self.ask.priority;
Expand Down