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
17 changes: 11 additions & 6 deletions rs/moq-flate/src/snapshot/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,17 @@ impl Consumer {
latest = Some(value);
}
Poll::Ready(Ok(None)) => self.group = None,
Poll::Ready(Err(
err @ (moq_net::Error::Old
| moq_net::Error::Evicted
| moq_net::Error::Lagged
| moq_net::Error::GroupTooLarge),
)) => {
// Judged by stream code, so a group the publisher reset as old is the same loss as
// one this side dropped.
Poll::Ready(Err(err))
if matches!(
moq_net::StreamError::from(&err),
moq_net::StreamError::Old
| moq_net::StreamError::Evicted
| moq_net::StreamError::TooFarBehind
| moq_net::StreamError::GroupTooLarge
) =>
{
// A later group starts a fresh snapshot and compression window.
tracing::warn!(track = self.track.name(), group = group.sequence, error = ?err,
"snapshot group lost; waiting for a newer one");
Expand Down
59 changes: 31 additions & 28 deletions rs/moq-flate/src/snapshot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,34 +152,37 @@ mod test {
/// replacement rather than ending the reader.
#[test]
fn a_lost_group_waits_for_its_replacement() {
let track = moq_net::broadcast::Info::new()
.produce()
.create_track("test", timed())
.unwrap();
let mut consumer = consume(track.subscribe(None), false);
let waiter = kio::Waiter::noop();

// Group 0 delivers a value, then stays open with the reader parked on its next frame.
let mut group = track.create_group(moq_net::group::Info { sequence: 0 }).unwrap();
group
.write_frame(moq_net::Timestamp::now(), Bytes::from_static(b"one"))
.unwrap();
assert!(matches!(consumer.poll_latest(&waiter), Poll::Ready(Ok(Some(v))) if v.value == "one"));
assert!(consumer.poll_latest(&waiter).is_pending());

// The relay reclaims the group out from under the reader.
group.abort(moq_net::Error::Old).unwrap();
assert!(
consumer.poll_latest(&waiter).is_pending(),
"a lost group must not end the reader"
);

// The replacement arrives and the reader picks up where the value now lives.
let mut group = track.create_group(moq_net::group::Info { sequence: 1 }).unwrap();
group
.write_frame(moq_net::Timestamp::now(), Bytes::from_static(b"two"))
.unwrap();
assert!(matches!(consumer.poll_latest(&waiter), Poll::Ready(Ok(Some(v))) if v.value == "two"));
// Lost on this side, then reset by the publisher: the reader sees the same loss either way.
for lost in [moq_net::Error::Old, moq_net::Error::Stream(moq_net::StreamError::Old)] {
let track = moq_net::broadcast::Info::new()
.produce()
.create_track("test", timed())
.unwrap();
let mut consumer = consume(track.subscribe(None), false);
let waiter = kio::Waiter::noop();

// Group 0 delivers a value, then stays open with the reader parked on its next frame.
let mut group = track.create_group(moq_net::group::Info { sequence: 0 }).unwrap();
group
.write_frame(moq_net::Timestamp::now(), Bytes::from_static(b"one"))
.unwrap();
assert!(matches!(consumer.poll_latest(&waiter), Poll::Ready(Ok(Some(v))) if v.value == "one"));
assert!(consumer.poll_latest(&waiter).is_pending());

// The group is lost out from under the reader.
group.abort(lost).unwrap();
assert!(
consumer.poll_latest(&waiter).is_pending(),
"a lost group must not end the reader"
);

// The replacement arrives and the reader picks up where the value now lives.
let mut group = track.create_group(moq_net::group::Info { sequence: 1 }).unwrap();
group
.write_frame(moq_net::Timestamp::now(), Bytes::from_static(b"two"))
.unwrap();
assert!(matches!(consumer.poll_latest(&waiter), Poll::Ready(Ok(Some(v))) if v.value == "two"));
}
}

/// A stamped payload is written at its capture time, and the returned size is the encoded frame
Expand Down
17 changes: 11 additions & 6 deletions rs/moq-json/src/snapshot/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,17 @@ impl<T: DeserializeOwned> Consumer<T> {
advanced = Some(frame.timestamp);
}
Poll::Ready(Ok(None)) => self.group = None,
Poll::Ready(Err(
err @ (moq_net::Error::Old
| moq_net::Error::Evicted
| moq_net::Error::Lagged
| moq_net::Error::GroupTooLarge),
)) => {
// Judged by stream code, so a group the publisher reset as old is the same loss as
// one this side dropped.
Poll::Ready(Err(err))
if matches!(
moq_net::StreamError::from(&err),
moq_net::StreamError::Old
| moq_net::StreamError::Evicted
| moq_net::StreamError::TooFarBehind
| moq_net::StreamError::GroupTooLarge
) =>
{
// A later group starts a fresh snapshot and compression window.
tracing::warn!(track = self.track.name(), group = group.sequence, error = ?err,
"snapshot group lost; waiting for a newer one");
Expand Down
57 changes: 30 additions & 27 deletions rs/moq-json/src/snapshot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,34 +237,37 @@ mod test {
/// catalog group aged out of the relay cache underneath it.
#[test]
fn a_lost_group_waits_for_its_replacement() {
let track = moq_net::broadcast::Info::new()
.produce()
.create_track("test", timed())
.unwrap();
let mut consumer = Consumer::<Value>::new(track.subscribe(None), consumer::Config::default());
let waiter = kio::Waiter::noop();

// Group 0 delivers a value, then stays open with the reader parked on its next frame.
let mut group = track.create_group(moq_net::group::Info { sequence: 0 }).unwrap();
group
.write_frame(moq_net::Timestamp::now(), Bytes::from_static(br#"{"a":1}"#))
.unwrap();
assert!(matches!(consumer.poll_latest(&waiter), Poll::Ready(Ok(Some(v))) if v.value == json!({ "a": 1 })));
assert!(consumer.poll_latest(&waiter).is_pending());

// The relay reclaims the group out from under the reader.
group.abort(moq_net::Error::Old).unwrap();
assert!(
consumer.poll_latest(&waiter).is_pending(),
"a lost group must not end the reader"
);
// Lost on this side, then reset by the publisher: the reader sees the same loss either way.
for lost in [moq_net::Error::Old, moq_net::Error::Stream(moq_net::StreamError::Old)] {
let track = moq_net::broadcast::Info::new()
.produce()
.create_track("test", timed())
.unwrap();
let mut consumer = Consumer::<Value>::new(track.subscribe(None), consumer::Config::default());
let waiter = kio::Waiter::noop();

// The replacement arrives and the reader picks up where the value now lives.
let mut group = track.create_group(moq_net::group::Info { sequence: 1 }).unwrap();
group
.write_frame(moq_net::Timestamp::now(), Bytes::from_static(br#"{"a":2}"#))
.unwrap();
assert!(matches!(consumer.poll_latest(&waiter), Poll::Ready(Ok(Some(v))) if v.value == json!({ "a": 2 })));
// Group 0 delivers a value, then stays open with the reader parked on its next frame.
let mut group = track.create_group(moq_net::group::Info { sequence: 0 }).unwrap();
group
.write_frame(moq_net::Timestamp::now(), Bytes::from_static(br#"{"a":1}"#))
.unwrap();
assert!(matches!(consumer.poll_latest(&waiter), Poll::Ready(Ok(Some(v))) if v.value == json!({ "a": 1 })));
assert!(consumer.poll_latest(&waiter).is_pending());

// The group is lost out from under the reader.
group.abort(lost).unwrap();
assert!(
consumer.poll_latest(&waiter).is_pending(),
"a lost group must not end the reader"
);

// The replacement arrives and the reader picks up where the value now lives.
let mut group = track.create_group(moq_net::group::Info { sequence: 1 }).unwrap();
group
.write_frame(moq_net::Timestamp::now(), Bytes::from_static(br#"{"a":2}"#))
.unwrap();
assert!(matches!(consumer.poll_latest(&waiter), Poll::Ready(Ok(Some(v))) if v.value == json!({ "a": 2 })));
}
}

/// Nothing replaces a lost group once the track is finished, so the reader ends cleanly on the
Expand Down
17 changes: 11 additions & 6 deletions rs/moq-json/src/window/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,17 @@ impl<T: DeserializeOwned> Consumer<T> {
};

match group.poll_read_frame(waiter) {
Poll::Ready(Err(
moq_net::Error::Old
| moq_net::Error::Lagged
| moq_net::Error::Evicted
| moq_net::Error::GroupTooLarge,
)) => {
// Judged by stream code, so a group the publisher reset as old is the same loss as
// one this side dropped.
Poll::Ready(Err(err))
if matches!(
moq_net::StreamError::from(&err),
moq_net::StreamError::Old
| moq_net::StreamError::TooFarBehind
| moq_net::StreamError::Evicted
| moq_net::StreamError::GroupTooLarge
) =>
{
// This group is no longer complete, but the next one starts with a checkpoint
// that can account for everything this reader missed.
self.group = None;
Expand Down
5 changes: 5 additions & 0 deletions rs/moq-json/src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,16 @@ mod test {

#[test]
fn consumer_resumes_at_a_checkpoint_after_losing_a_group() {
// Each loss as this side raises it, then as a publisher's reset carries it.
for err in [
moq_net::Error::Old,
moq_net::Error::Lagged,
moq_net::Error::Evicted,
moq_net::Error::GroupTooLarge,
moq_net::Error::Stream(moq_net::StreamError::Old),
moq_net::Error::Stream(moq_net::StreamError::TooFarBehind),
moq_net::Error::Stream(moq_net::StreamError::Evicted),
moq_net::Error::Stream(moq_net::StreamError::GroupTooLarge),
] {
let track = moq_net::broadcast::Info::new()
.produce()
Expand Down
Loading