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: 8 additions & 2 deletions js/hang/src/container/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ function micros(timestamp: Duration): number {
* still refuses a frame after the finish.
*/
export interface Finished {
/** Abort the track with an error; see {@link Producer.abort}. */
/**
* Mirrors the Rust `container::Finished::abort`, and like it changes nothing a reader sees: every
* group finished, so readers still draining get the rest of the track and its clean end, not `err`.
*/
abort(err: Error): void;
}

Expand Down Expand Up @@ -282,7 +285,10 @@ export class Producer {
return this;
}

/** Abort the current group and the track with `err`, which readers see in place of a clean end. */
/**
* Abort the current group and the track with `err`, which readers see in place of a clean end. A
* no-op after {@link finish}: the track is already complete.
*/
abort(err: Error) {
this.#group?.abort(err);
this.#group = undefined;
Expand Down
10 changes: 8 additions & 2 deletions js/json/src/window/producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export interface Finished<T> {
readonly window: T[];
/** Absolute index of the oldest retained record; see {@link Producer.offset}. */
readonly offset: number;
/** Abort the track with an error; see {@link Producer.abort}. */
/**
* Mirrors the Rust `window::Finished::abort`, and like it changes nothing a reader sees: every group
* finished, so readers still draining get the rest of the window and its clean end, not `err`.
*/
abort(err: Error): void;
}

Expand Down Expand Up @@ -192,7 +195,10 @@ export class Producer<T> {
return this;
}

/** Abort the track with `err`, so readers see the cause rather than a complete window. Idempotent. */
/**
* Abort the track with `err`, so readers see the cause rather than a complete window. Idempotent,
* and a no-op after {@link finish}: the window is already complete.
*/
abort(err: Error): void {
this.#close(err);
}
Expand Down
15 changes: 15 additions & 0 deletions js/json/src/window/window.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,3 +644,18 @@ test("finishing returns a window that reads but takes no edit", () => {
// @ts-expect-error a finished window takes no record
expect(() => finished.push({ n: 2 }, key())).toThrow("track is closed");
});

// Mirrors the Rust `aborting_a_finished_window_still_drains`: an abort after finish changes nothing a
// reader sees, since every group finished, so one still draining gets the rest and the clean end.
test("aborting a finished window still drains", async () => {
const track = new Track.Producer("test");
const consumer = new Consumer<Rec>({ track: track.subscribe() });
const producer = new Producer<Rec>({ track });
producer.push({ n: 0 }, key());
producer.push({ n: 1 }, key());
expect((await consumer.next())?.value).toEqual({ push: { index: 0, value: { n: 0 } } });

producer.finish().abort(new NetError.Stream(StreamCode.Cancel));
expect((await consumer.next())?.value).toEqual({ push: { index: 1, value: { n: 1 } } });
expect(await consumer.next()).toBeUndefined();
});
9 changes: 0 additions & 9 deletions quest/m1/precut-fixes/window-finished-abort.md

This file was deleted.

5 changes: 3 additions & 2 deletions rs/moq-audio/src/encode/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,8 +944,9 @@ impl Finished {
self.track.demand()
}

/// Abort the track with `err`, so subscribers that have not drained it see the real cause; see
/// [`Producer::abort`].
/// Abort the track with `err`; see [`Producer::abort`]. Readers still draining get the end the
/// track declared instead once every group below it finished: the clean end after
/// [`Producer::finish`], or the capture's error when the source failed.
pub fn abort(self, err: moq_net::Error) {
self.track.abort(err);
}
Expand Down
3 changes: 2 additions & 1 deletion rs/moq-json/src/snapshot/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ impl<T> Finished<T> {
take(&self.inner).track.inner.demand()
}

/// Release the track's cache, reporting `err` to readers that have not drained it.
/// Abort the track with `err`; see [`moq_net::track::Finished::abort`]. Readers still draining
/// get the clean end instead once every group below the end finished.
pub fn abort(self, err: moq_net::Error) -> Result<()> {
take(&self.inner).abort(err.into());
Ok(())
Expand Down
3 changes: 2 additions & 1 deletion rs/moq-json/src/stream/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ impl<T> Finished<T> {
self.inner.lock().unwrap().track.inner.demand()
}

/// Release the track's cache, reporting `err` to readers that have not drained it.
/// Abort the track with `err`; see [`moq_net::track::Finished::abort`]. Readers still draining
/// get the clean end instead once every group below the end finished.
pub fn abort(self, err: moq_net::Error) -> Result<()> {
self.inner.lock().unwrap().track.abort(err);
Ok(())
Expand Down
20 changes: 20 additions & 0 deletions rs/moq-json/src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,26 @@ mod test {
let _ = Encoder::<Value>::new(config);
}

/// An abort after finish changes nothing a reader sees: every group finished, so one still
/// draining gets the rest of the window and the clean end, not the error.
#[test]
fn aborting_a_finished_window_still_drains() {
let (mut producer, track) = producer(Config::default());
let mut consumer = consumer(track);
producer.push(&rec(0), key()).unwrap();
producer.push(&rec(1), key()).unwrap();
let waiter = kio::Waiter::noop();
let mut next = || match consumer.poll_next(&waiter) {
Poll::Ready(next) => next.unwrap().map(|event| event.value),
Poll::Pending => panic!("expected a window event or its end"),
};
assert!(matches!(next(), Some(Event::Push { index: 0, .. })));

producer.finish().unwrap().abort(moq_net::Error::Cancel).unwrap();
assert!(matches!(next(), Some(Event::Push { index: 1, .. })));
assert!(next().is_none());
}

fn consumer(track: moq_net::track::Subscriber) -> Consumer<Value> {
Consumer::new(track, consumer::Config::default())
}
Expand Down
3 changes: 2 additions & 1 deletion rs/moq-json/src/window/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ impl<T> Finished<T> {
self.inner.lock().unwrap().encoder.range()
}

/// Release the track's cache, reporting `err` to readers that have not drained it.
/// Abort the track with `err`; see [`moq_net::track::Finished::abort`]. Readers still draining
/// get the clean end instead once every group below the end finished.
pub fn abort(self, err: moq_net::Error) -> Result<()> {
self.inner.lock().unwrap().abort(err.into());
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions rs/moq-mux/src/container/flv/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,8 @@ pub struct Finished<E: crate::catalog::hang::CatalogExt = ()> {
}

impl<E: crate::catalog::hang::CatalogExt> Finished<E> {
/// Release every track's cache, reporting `err` to readers that have not drained it; see
/// [`Import::abort`].
/// Abort every track with `err`; see [`Import::abort`]. Readers still draining a track get its
/// clean end instead once every group below its end finished.
pub fn abort(self, err: moq_net::Error) {
self.import.abort(err);
}
Expand Down
4 changes: 2 additions & 2 deletions rs/moq-mux/src/container/fmp4/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1921,8 +1921,8 @@ pub struct Finished<E: crate::catalog::hang::CatalogExt = ()> {
}

impl<E: crate::catalog::hang::CatalogExt> Finished<E> {
/// Release every track's cache, reporting `err` to readers that have not drained it; see
/// [`Import::abort`].
/// Abort every track with `err`; see [`Import::abort`]. Readers still draining a track get its
/// clean end instead once every group below its end finished.
pub fn abort(self, err: moq_net::Error) {
self.import.abort(err);
}
Expand Down
4 changes: 2 additions & 2 deletions rs/moq-mux/src/container/mkv/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,8 +1033,8 @@ pub struct Finished<E: crate::catalog::hang::CatalogExt = ()> {
}

impl<E: crate::catalog::hang::CatalogExt> Finished<E> {
/// Release every track's cache, reporting `err` to readers that have not drained it; see
/// [`Import::abort`].
/// Abort every track with `err`; see [`Import::abort`]. Readers still draining a track get its
/// clean end instead once every group below its end finished.
pub fn abort(self, err: moq_net::Error) {
self.import.abort(err);
}
Expand Down
5 changes: 3 additions & 2 deletions rs/moq-mux/src/container/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,8 +1179,9 @@ where
self.producer.estimate()
}

/// Release the track's cache, reporting `err` to readers that have not drained it; see
/// [`moq_net::track::Finished::abort`].
/// Abort the track with `err`; see [`moq_net::track::Finished::abort`]. Readers still draining get the end
/// the track declared instead once every group below it finished: the clean end after [`Producer::finish`],
/// or the error [`Producer::fail`] gave.
pub fn abort(self, err: moq_net::Error) {
self.producer.abort(err);
}
Expand Down
4 changes: 2 additions & 2 deletions rs/moq-mux/src/container/ts/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2056,8 +2056,8 @@ impl<E: catalog::Catalog> Finished<E> {
self.import.stats()
}

/// Release every track's cache, reporting `err` to readers that have not drained it; see
/// [`Import::abort`].
/// Abort every track with `err`; see [`Import::abort`]. Readers still draining a track get its
/// clean end instead once every group below its end finished.
pub fn abort(self, err: moq_net::Error) {
self.import.abort(err);
}
Expand Down
4 changes: 2 additions & 2 deletions rs/moq-mux/src/container/ts/passthrough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ impl<E: super::Catalog> Finished<E> {
self.passthrough.track()
}

/// Release the track's cache, reporting `err` to readers that have not drained it; see
/// [`Passthrough::abort`].
/// Abort the track with `err`; see [`Passthrough::abort`]. Readers still draining get the clean end
/// instead once every group below the end finished.
pub fn abort(self, err: moq_net::Error) {
self.passthrough.abort(err);
}
Expand Down
3 changes: 2 additions & 1 deletion rs/moq-mux/src/container/ts/republish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ impl Finished {
self.import.stats()
}

/// Release every track's cache, reporting `err` to readers that have not drained it.
/// Abort every track with `err`. Readers still draining a track get its clean end instead once
/// every group below its end finished.
pub fn abort(self, err: moq_net::Error) {
self.import.abort(err);
}
Expand Down
3 changes: 2 additions & 1 deletion rs/moq-mux/src/import/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ pub struct Finished<E: crate::container::ts::Catalog = ()> {
}

impl<E: crate::container::ts::Catalog> Finished<E> {
/// Release every track's cache, reporting `err` to readers that have not drained it.
/// Abort every track with `err`. Readers still draining a track get its clean end instead once
/// every group below its end finished.
pub fn abort(self, err: moq_net::Error) {
match self.inner {
FinishedImpl::Fmp4(finished) => finished.abort(err),
Expand Down
4 changes: 2 additions & 2 deletions rs/moq-mux/src/import/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,8 +933,8 @@ impl Finished {
}
}

/// Release the track's cache, reporting `err` to readers that have not drained it; see
/// [`moq_net::track::Finished::abort`].
/// Abort the track with `err`; see [`moq_net::track::Finished::abort`]. Readers still draining get the clean end
/// instead once every group below the end finished.
pub fn abort(self, err: moq_net::Error) {
match self.inner {
FinishedKind::Video(track) => track.abort(err),
Expand Down
3 changes: 2 additions & 1 deletion rs/moq-net/src/model/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5460,7 +5460,8 @@ impl Finished {

/// Abort the track with the given error; see [`Producer::abort`].
///
/// Once every group below the end finished, readers still get the clean end.
/// Once every group below the end finished, readers still get the end the track declared: the
/// clean end after [`Producer::finish`], or the error [`Producer::fail`] gave.
pub fn abort(self, err: Error) -> Result<()> {
self.producer.abort(err)
}
Expand Down
3 changes: 2 additions & 1 deletion rs/moq-video/src/encode/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ impl Finished {
self.track.demand()
}

/// Abort the track with `err`, so subscribers that have not drained it see the real cause.
/// Abort the track with `err`; see [`moq_net::track::Finished::abort`]. Readers still draining
/// get the clean end instead once every group below the end finished.
pub fn abort(self, err: moq_net::Error) {
self.track.abort(err);
}
Expand Down