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
2 changes: 1 addition & 1 deletion doc/concept/moq-lite.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ Each subscription carries the knobs that decide behavior under congestion:
On moq-lite 05 and later, a publisher explicitly reports groups that will not arrive.
This lets a finished subscription settle without waiting for missing groups.
A reader of a reported group, including one still arriving, ends with the publisher's error, such as `OLD` or `NOT_FOUND`.
On moq-lite 05 and 06 that code is application-specific, so every reported group ends with `NOT_FOUND` there.
Before moq-lite 07 that code is application-specific, so every reported group ends with `OLD`.
Datagram delivery stays best effort.

Ranges are both a request and a filter. A subscriber reads only the groups its
Expand Down
2 changes: 1 addition & 1 deletion drafts/draft-lcurley-moq-lite.md
Original file line number Diff line number Diff line change
Expand Up @@ -1871,7 +1871,7 @@ The `Message Length` describes the payload size on the wire.
- Switched every variable-length integer, including SETUP parameter values, from QUIC's two-bit length prefix to moq-transport's leading-ones encoding, widening the range to 64 bits.
- Hid routes with a `.`-prefixed segment below the requested prefix from announce discovery, and added the ANNOUNCE_REQUEST `Hidden` field to opt in.
- Restored SUBSCRIBE_DROP (type 0x2), replacing Stream Count on SUBSCRIBE_END. Every sequence is accounted for by a Group Stream, a datagram, or a drop; a publisher SHOULD send a drop as soon as it gives a sequence up.
- SUBSCRIBE_DROP's Error Code is a stream error code, which ends the dropped groups' readers, including one still arriving. In lite-05 and lite-06 it is application-specific, so a subscriber there reads every drop as NOT_FOUND.
- SUBSCRIBE_DROP's Error Code is a stream error code, which ends the dropped groups' readers, including one still arriving. In lite-05 and lite-06 it is application-specific, so a subscriber there reads every drop as OLD.
- SUBSCRIBE_END declares the final boundary while lower groups can still be in flight; the Subscribe Stream FIN follows once every Group Stream has finished or been reset.
- Added the Spread Hash tie-break after the shortest path: a hash of the requested path and the route's Hop IDs, so equal-cost advertisers of one prefix share its paths.
- Skipped the Spread Hash for a route a publisher announced directly at the requested path.
Expand Down
16 changes: 16 additions & 0 deletions js/json/src/snapshot/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,22 @@ test("a compressed delta is gated on its encoded size, not its plaintext", async
expect(values[values.length - 1]).toEqual(patched);
});

// A publisher gives up a group a reader is still on once a newer one supersedes it, which every
// moq-lite version reports as OLD. The reader skips to the newer snapshot instead of failing.
test("snapshot consumer skips a group the publisher dropped mid-read", async () => {
const track = new Track.Producer("test");
const consumer = new Consumer<Value>({ track: track.subscribe() });
const first = track.appendGroup();
first.writeFrame({ payload: new TextEncoder().encode('{"v":0}'), timestamp: Time.Timestamp.now() });
expect((await consumer.latest())?.value).toEqual({ v: 0 });

const next = consumer.latest();
first.close(new NetError.Stream(StreamCode.Old));
const second = track.appendGroup();
second.writeFrame({ payload: new TextEncoder().encode('{"v":1}'), timestamp: Time.Timestamp.now() });
expect((await next)?.value).toEqual({ v: 1 });
});

// A malformed or failed group must reach the caller; only an explicit retention gap is resumable.
test("snapshot consumer propagates a non-gap frame failure", async () => {
const track = new Track.Producer("test");
Expand Down
2 changes: 1 addition & 1 deletion js/net/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The wire messages (`Lite.Subscribe`, `Lite.TrackInfo`, `Ietf.Subscribe`, ...) ho

A group the publisher cut, or named in `SUBSCRIBE_DROP`, after a `Track.Subscriber` saw it is now handed out, and its reads reject with the publisher's `StreamError`; before, it was skipped or ended cleanly.
A group already held rejects the same way when the drop lands, even while its stream is still arriving.
On lite-05 and lite-06 the code is always `StreamCode.NotFound`.
On lite-05 and lite-06 the code is always `StreamCode.Old`.
Treat a rejected group read as the loss of that group and keep reading the track, rather than ending the subscription.

### A claim answers by publishing (#5678)
Expand Down
8 changes: 4 additions & 4 deletions js/net/src/lite/subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,13 +693,13 @@ export class SubscribeDrop {
/**
* The error the dropped groups' readers end with, as `version` reads the code.
*
* Before lite-07 the code is the application's, so every drop reads as NOT_FOUND: the
* groups are not there to deliver.
* Before lite-07 the code is the application's, so every drop reads as OLD: the publisher
* gave the groups up, and a reader moves on to a newer one as it would past a superseded group.
*/
cause(version: Version): Error {
if (!hasDropCode(version)) return new StreamError(StreamCode.NotFound, { message: "dropped" });
if (!hasDropCode(version)) return new StreamError(StreamCode.Old);
if (this.error > 0xffff_ffff)
return new StreamError(StreamCode.Internal, { message: `dropped: ${this.error}` });
return new StreamError(StreamCode.Internal, { message: `invalid drop code: ${this.error}` });
return fromTransport({ source: "stream", streamErrorCode: this.error });
}

Expand Down
11 changes: 9 additions & 2 deletions js/net/src/lite/tail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ describe.each([Version.DRAFT_05, Version.DRAFT_06, Version.DRAFT_07])("%s", (ver
});

// Lite-07 carries a stream error code; earlier versions an application one, so the same
// bytes read as NOT_FOUND there.
// bytes read as OLD there.
test("a SUBSCRIBE_DROP ends a group still arriving, before the FIN", async () => {
const { subscriber, reader, respond } = await subscribed(version, Milli(60_000));
await respond({ start: new SubscribeStart(0) });
Expand All @@ -297,8 +297,15 @@ describe.each([Version.DRAFT_05, Version.DRAFT_06, Version.DRAFT_07])("%s", (ver
(err: unknown) => err,
);
expect(err).toBeInstanceOf(StreamError);
expect((err as StreamError).code).toBe(version === Version.DRAFT_07 ? StreamCode(70) : StreamCode.NotFound);
expect((err as StreamError).code).toBe(version === Version.DRAFT_07 ? StreamCode(70) : StreamCode.Old);
expect(reader.closed.peek()).toBeUndefined();

// The track goes on: the next group still reaches the reader.
const following = groupStream(subscriber, 1);
following.write("1.0");
const next = await reader.recvGroup();
expect(next?.sequence).toBe(1);
expect(await next?.readString()).toBe("1.0");
subscriber.close();
});

Expand Down
2 changes: 1 addition & 1 deletion rs/moq-net/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Clamp timestamps you build from unbounded input to `(1 << 61) - 1`.

A group the publisher cut, or named in `SUBSCRIBE_DROP`, after a `track::Subscriber` saw it is now handed out, and reading it fails with the publisher's error; before, it was skipped or ended cleanly.
A group already held fails the same way when the drop lands, even while its stream is still arriving.
On lite-05 and lite-06 the error is always `Error::Stream(StreamError::NotFound)`.
On lite-05 and lite-06 the error is always `Error::Stream(StreamError::Old)`.
Treat a failed group read as the loss of that group and keep reading the track, rather than ending the subscription.

### A claim answers by publishing (#5678)
Expand Down
5 changes: 3 additions & 2 deletions rs/moq-net/src/lite/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,12 @@ impl SubscribeDrop {
/// The error the dropped groups' readers end with, as `version` reads the code.
///
/// Before lite-07 the code is the application's, so every drop reads as
/// [`StreamError::NotFound`]: the groups are not there to deliver.
/// [`StreamError::Old`]: the publisher gave the groups up, and a reader moves on to a
/// newer one as it would past a superseded group.
pub fn error(&self, version: Version) -> StreamError {
match version.has_drop_code() {
true => u32::try_from(self.error).map_or(StreamError::Internal, |code| version.decode_stream_code(code)),
false => StreamError::NotFound,
false => StreamError::Old,
}
}
}
Expand Down
17 changes: 15 additions & 2 deletions rs/moq-net/src/lite/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3522,7 +3522,7 @@ mod tests {

/// A SUBSCRIBE_DROP ends a group still arriving now, with its Error Code on lite-07.
/// Earlier versions carry an application code there, so the same bytes read as
/// NOT_FOUND.
/// OLD.
#[moq_clock::test]
async fn a_subscribe_drop_ends_an_arriving_group_with_its_code() {
for version in [Version::Lite05, Version::Lite06, Version::Lite07] {
Expand Down Expand Up @@ -3570,6 +3570,7 @@ mod tests {
let broadcast = crate::broadcast::Info::new().produce();
let request = broadcast.reserve_track("video").unwrap();
let serving = ServeLoop::new(&serve, request, crate::track::Info::timed());
let producer = serving.serving.clone();
let mut arriving = serving.serving.create_group(group::Info { sequence: 2 }).unwrap();
arriving.write_frame(crate::Timestamp::ZERO, b"2".as_slice()).unwrap();
let mut reader = broadcast
Expand All @@ -3592,13 +3593,25 @@ mod tests {

let expected = match version {
Version::Lite07 => crate::StreamError::App(5),
_ => crate::StreamError::NotFound,
_ => crate::StreamError::Old,
};
let res = group.read_frame().now_or_never();
assert!(
matches!(&res, Some(Err(Error::Stream(err))) if *err == expected),
"{version:?}: {res:?}"
);

// The track goes on: the next group still reaches the reader.
let mut following = producer.create_group(group::Info { sequence: 3 }).unwrap();
following.write_frame(crate::Timestamp::ZERO, b"3".as_slice()).unwrap();
let mut next = reader
.recv_group()
.now_or_never()
.expect("the next group")
.unwrap()
.unwrap();
assert_eq!(next.sequence, 3, "{version:?}");
assert_eq!(next.read_frame().await.unwrap().unwrap().payload.as_ref(), b"3");
}
}

Expand Down
17 changes: 14 additions & 3 deletions rs/moq-net/src/model/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3149,11 +3149,22 @@ struct InFlight {
routes: super::resume::Producer,
// Kept for its readers: the logical track, the query holding its copy, and the copy's
// subscription.
_accepted: Option<track::Producer>,
accepted: Option<track::Producer>,
_copy: Option<track::Querying>,
_held: Option<kio::Pending<track::Subscribing>>,
}

impl InFlight {
/// Let go once its last reader left. Nobody reads the logical track any more, so it ends
/// as a cancel rather than as a producer dropped unfinished.
fn release(self) {
self.routes.release();
if let Some(accepted) = self.accepted {
let _ = accepted.abort(Error::Cancel);
}
}
}

/// Drives one front until it ends, then holds the tracks it left in flight until
/// their last reader leaves, or until nothing owns the origin: a reader never keeps
/// the driver from finishing.
Expand All @@ -3172,7 +3183,7 @@ async fn run_front(task: FrontTask, origin: TasksWeak) {
for io in std::mem::take(&mut in_flight) {
match io.weak.poll_unused(waiter) {
Poll::Pending => in_flight.push(io),
Poll::Ready(_) => io.routes.release(),
Poll::Ready(_) => io.release(),
}
}
match in_flight.is_empty() {
Expand Down Expand Up @@ -3687,7 +3698,7 @@ async fn serve_front(task: FrontTask) -> Vec<InFlight> {
in_flight.push(InFlight {
weak,
routes,
_accepted: accepted,
accepted,
_copy: copy.map(|(_, _, query)| query),
_held: held,
});
Expand Down
Loading