diff --git a/doc/concept/standard.md b/doc/concept/standard.md index ae384cd4d08..15dd7bf38e0 100644 --- a/doc/concept/standard.md +++ b/doc/concept/standard.md @@ -28,7 +28,8 @@ subset drops. What a peer actually observes against this implementation: - **Pull.** Subscribers ask. Single-track `PUBLISH` offers are declined, unless they answer our `SUBSCRIBE_TRACKS` (below); announce a namespace and serve the resulting subscriptions. Announcements go out unsolicited. A client asks only for the prefixes its readers watch, and a server or relay link for every prefix it may discover. We never hold two overlapping requests at a peer that did not declare solicit: a broader one replaces the narrower ones once they are closed. The solicit `SETUP` option makes us wait to be asked. Without it, a peer also gets each match as a `NAMESPACE` on its `SUBSCRIBE_NAMESPACE` stream, so it hears the namespace twice. We never send `PUBLISH`. - **We list no tracks by `PUBLISH`.** Rust and JavaScript refuse each `SUBSCRIBE_TRACKS` with `NOT_SUPPORTED`, and the session stays up. Our own peers list tracks over moq-lite instead. - **A Rust TRACKS listing sends `SUBSCRIBE_TRACKS` upstream, only on demand.** Listing a broadcast from a moq-transport peer sends `SUBSCRIBE_TRACKS` with `FORWARD=0` while someone lists it, never on connect, announce, or subscribe, so a peer that refuses, resets, or ignores it affects only that listing. Each listed track's paused `PUBLISH` is its upstream copy, which a reader resumes rather than subscribing again. Only a `PUBLISH_DONE` with `TRACK_ENDED` removes a listed track, and it lists as finished; any other end fails the listing, and readers list again. Our own moq-transport publishers refuse it, so a Rust listing of one fails. -- **History is served one group at a time.** Our moq-transport publishers answer a `FETCH` only within one group, a draft-18 joining `FETCH` for the subscription's current group head, and a draft 20+ fill for the largest group's head. Whole-group fetches wait for an open group to finish. Both implementations accept and ignore `FILL_TIMEOUT`, including zero. A JavaScript subscription joins at the current group: on draft 18 it fetches the group's head with a Relative Joining `FETCH`, and from draft 20 asks for it with a fill. Datagrams are never fetchable. Subscribers still request ranges upstream, one per run of missing groups; a third-party publisher can answer those ranges and mark their gaps. A Rust reader that only fetches learns the track from `TRACK_STATUS`, so a finished track stays fetchable; a reader whose publisher refuses `TRACK_STATUS` as `NOT_SUPPORTED` still subscribes. +- **History is served one group at a time.** Our moq-transport publishers answer a `FETCH` only within one group, a draft-18 joining `FETCH` for the subscription's current group head, and a draft 20+ fill for the largest group's head. Whole-group fetches wait for an open group to finish. Both implementations accept and ignore `FILL_TIMEOUT`, including zero. A JavaScript subscription joins at the current group: on draft 18 it fetches the group's head with a Relative Joining `FETCH`, and from draft 20 asks for it with a fill. Datagrams are never fetchable. Subscribers still request ranges upstream, one per run of missing groups; a third-party publisher can answer those ranges and mark their gaps. A Rust reader that only fetches learns the track from `TRACK_STATUS`, so a finished track stays fetchable; a refused `TRACK_STATUS` fails that reader's request, whatever the code, rather than falling back to a `SUBSCRIBE`. +- **A requester's FIN.** On draft 18 a requester finishing its stream cancels its request, except after `TRACK_STATUS`: nothing can follow it, so the FIN only ends the requester's input and the request is still answered. From draft 20 a FIN never cancels; a reset or `STOP_SENDING` does. - **Compression.** Rust peers exchange compressed tracks when both offer the [Flate extension](/draft/moq-flate). Other peers receive one shared inflated copy. A publisher that seals the compression declaration makes that fallback unavailable: an incompatible peer is refused, preserving the sealed metadata. JavaScript does not offer the IETF extension. - **Timing.** A track whose `SUBSCRIBE_OK` or `PUBLISH` declares no `TIMESCALE` is untimed. A `SUBSCRIBE` or `FETCH` with `INCLUDE_PROPERTIES=0` gets no `TIMESCALE` in its `SUBSCRIBE_OK` or `FETCH_OK`, so its objects go out unstamped. A Rust reader that never subscribed takes the units from `TRACK_STATUS`, and still asks for the properties whenever it subscribes to or fetches a timed track. - **Strict SETUP and parameters.** Repeated unknown `SETUP` options, GREASE included, are accepted if well-formed; a repeated known option is rejected. A `GROUP_ORDER` other than Ascending (1) or Descending (2) closes the session. An unknown message parameter, or one defined only for another message, closes the session. Other malformed control input closes the session with the draft's code too, such as a server `SETUP` carrying `PATH` or `AUTHORITY`, a namespace field ending in `/` (it would map to a path with an empty segment), a request cut short by FIN, or a second `GOAWAY` on one stream; a first `GOAWAY` on a request stream is legal. diff --git a/js/net/src/ietf/publisher.test.ts b/js/net/src/ietf/publisher.test.ts index 351c4059667..c8e3247cf9a 100644 --- a/js/net/src/ietf/publisher.test.ts +++ b/js/net/src/ietf/publisher.test.ts @@ -218,6 +218,8 @@ function requestStream(version: IetfVersion) { wire: () => new Reader(undefined, Uint8Array.from(written), version), send: (bytes: Uint8Array) => input.enqueue(bytes), cancel: () => input.error(new Error("request cancelled")), + /** FIN the request's side: the requester has nothing more to send. */ + finish: () => input.close(), /** * End the request as `version` cancels one: by FIN through draft 18, and by a reset * after. @@ -286,6 +288,33 @@ test("TRACK_STATUS is answered on every draft without subscribing", async () => } }); +// A requester may FIN right after TRACK_STATUS, since nothing can follow it (moxygen does). +// That only ends its input, so the request is still answered, on draft 18 too. +test("TRACK_STATUS finished at once is answered on every draft", async () => { + for (const version of IETF_VERSIONS) { + const pair = createMockTransportPair(ALPNS[version]); + const session = new NativeSession(pair.server, version, true); + const { pub, origin } = publisher(pair.server, { session }); + const requests = origin.requestsRoute(Path.from("room")).requested(); + + // The FIN arrives while the broadcast still resolves. + const { stream, wire, finish } = requestStream(version); + const task = pub.runTrackStatusRequest(trackStatus("room"), stream); + const pending = (await requests.next()).value; + if (!pending) throw new Error("no request for room"); + finish(); + const served = new BroadcastProducer(); + served.createTrack("video"); + hooks.acceptRequest(pending, served); + await task; + expect(await wire().u53()).toBe(TrackStatusOk.id); + + await requests.return?.(); + served.close(); + origin.close(); + } +}); + // A track that has published nothing answers without LARGEST_OBJECT. test("TRACK_STATUS for an empty track names no largest", async () => { const version = Version.DRAFT_22; diff --git a/js/net/src/ietf/publisher.ts b/js/net/src/ietf/publisher.ts index 5e81c425442..9f4d12ef0c6 100644 --- a/js/net/src/ietf/publisher.ts +++ b/js/net/src/ietf/publisher.ts @@ -2076,7 +2076,9 @@ export class Publisher { * @internal */ runTrackStatusRequest(msg: TrackStatusRequest, stream: Stream): Promise { - const request = new RequestStream(stream, this.#session, this.#quic); + // Nothing can follow a TRACK_STATUS, so a FIN only ends the requester's input; a reset or + // STOP_SENDING withdraws it. + const request = new RequestStream(stream, this.#session, this.#quic, { finCancels: false }); return request.serve(this.#runTrackStatusRequest(msg, request)); } diff --git a/js/net/src/ietf/request_stream.ts b/js/net/src/ietf/request_stream.ts index c1472a46a97..f32d42461a4 100644 --- a/js/net/src/ietf/request_stream.ts +++ b/js/net/src/ietf/request_stream.ts @@ -11,7 +11,14 @@ import type { Session } from "./session.ts"; import { MalformedAuthToken } from "./token.ts"; import { type IetfVersion, Version } from "./version.ts"; -/** Whether the draft treats the requester finishing its messages as cancellation. */ +/** + * Whether the requester finishing its messages withdraws a request on `version`. + * + * Draft 18 asks for a reset or STOP_SENDING (section 3.3.2) and names a FIN as a cancel only for + * SUBSCRIBE_NAMESPACE and SUBSCRIBE_TRACKS (section 6.1), but our own draft-18 requesters cancel + * by FIN, so we read one that way. TRACK_STATUS passes `false` instead: nothing can follow it, so + * a requester may FIN right after it (moxygen does). + */ function finCancels(version: IetfVersion): boolean { return version === Version.DRAFT_18; } @@ -147,6 +154,8 @@ export class RequestStream { readonly #stream: Stream; readonly #session: Session; readonly #quic?: WebTransport; + // Whether the peer's FIN withdraws the request, rather than only ending its input. + readonly #finCancels: boolean; // The next message, read ahead of whoever takes it. Unset until someone first waits. #ahead?: Promise; #taking = false; @@ -155,12 +164,16 @@ export class RequestStream { readonly #ended: Promise; #end!: () => void; - /** Own `stream` for a request on `session`, closing `quic` over the peer's violations. */ - constructor(stream: Stream, session: Session, quic?: WebTransport) { + /** + * Own `stream` for a request on `session`, closing `quic` over the peer's violations. The + * peer's FIN withdraws the request where `finCancels`, by default as the draft has it. + */ + constructor(stream: Stream, session: Session, quic?: WebTransport, options: { finCancels?: boolean } = {}) { this.#stream = stream; this.writer = stream.writer; this.#session = session; this.#quic = quic; + this.#finCancels = options.finCancels ?? finCancels(session.version); this.#ended = new Promise((resolve) => { this.#end = resolve; }); @@ -208,7 +221,7 @@ export class RequestStream { */ cancel(): void { if (this.#closed) return; - if (finCancels(this.#session.version)) this.writer.close(); + if (this.#finCancels) this.writer.close(); else this.writer.reset(new StreamError(StreamCode.Cancel, { message: "cancel" })); } @@ -256,12 +269,11 @@ export class RequestStream { // Start reading on the first wait. #read(): Promise { if (this.#ahead === undefined) { - const version = this.#session.version; this.#ahead = this.#readAhead(); // The read ahead stops at an untaken message, so watch for the peer's end apart from it. this.#stream.reader.closed.then( () => { - if (finCancels(version)) this.#end(); + if (this.#finCancels) this.#end(); }, () => this.#end(), ); @@ -279,7 +291,7 @@ export class RequestStream { const read = this.#readFramed(); read.then( (framed) => { - if (framed === undefined && finCancels(this.#session.version)) this.#end(); + if (framed === undefined && this.#finCancels) this.#end(); }, (err: unknown) => { if (err instanceof ProtocolViolation) this.abort(err); diff --git a/quest/m1/interop-coverage/README.md b/quest/m1/interop-coverage/README.md index 3f1326fd5c3..3006b2d6c74 100644 --- a/quest/m1/interop-coverage/README.md +++ b/quest/m1/interop-coverage/README.md @@ -44,7 +44,6 @@ coverage on `main` at `3ab6cbf81d`. ## Required -- [Draft-18 TRACK_STATUS FIN](/quest/m1/interop-coverage/draft18-status-fin.md) - a draft-18 TRACK_STATUS followed at once by a FIN is answered, so moqx-forwarded status requests reach moq-dev publishers - [JS subscribers FETCH](/quest/m1/interop-coverage/js-ietf-fetch.md) - `@moq/net` fetches past groups over moq-transport, and joins the CLI FETCH round ## Related diff --git a/quest/m1/interop-coverage/draft18-status-fin.md b/quest/m1/interop-coverage/draft18-status-fin.md deleted file mode 100644 index fddb0d801dc..00000000000 --- a/quest/m1/interop-coverage/draft18-status-fin.md +++ /dev/null @@ -1,33 +0,0 @@ -# [S] A draft-18 TRACK_STATUS followed at once by a FIN is answered - -## Goal - -On draft 18, a moq-net publisher (Rust and `@moq/net`) answers a TRACK_STATUS whose requester FINs right after sending it, with TRACK_STATUS_OK or REQUEST_ERROR, instead of resetting the stream with CANCELLED. A reset or STOP_SENDING still withdraws it. Every other draft-18 request keeps treating a requester FIN as a cancel. A unit test sends TRACK_STATUS plus an immediate FIN on drafts 18, 20 and 22 and gets an answer on each. `doc/concept/standard.md` no longer says a reader whose publisher refuses `TRACK_STATUS` still subscribes, where that reader only queries or fetches. - -## Plan - -Decided 2026-10-31 (maintainer, `/quest-import` of [moq-dev/moq#7438](https://github.com/moq-dev/moq/issues/7438) and [moq-dev/moq#7423](https://github.com/moq-dev/moq/issues/7423)). - -moxygen FINs right after TRACK_STATUS on draft 18+, since nothing can follow one. The WG agrees this is normal (moq-wg/moq-transport#1634), and draft 19 §3.3.2 says a FIN is not a cancellation. On draft 18, `rs/moq-net/src/ietf/request_stream.rs:11` `fin_cancels` treats any requester FIN as a withdrawal. So a TRACK_STATUS forwarded by a moxygen-based relay such as moqx is reset, and a moq-lite viewer behind moq-relay never subscribes. - -- Scope of the FIN rule: - - ✅ TRACK_STATUS only: a FIN only ends a TRACK_STATUS requester's input, on every draft. Our own draft-18 requesters keep cancelling other requests by FIN. - - FIN never cancels on draft 18 (except SUBSCRIBE_NAMESPACE/SUBSCRIBE_TRACKS, §6.1) - - Won't fix -- The fix is in [moq-dev/moq#7439](https://github.com/moq-dev/moq/pull/7439), an external contributor's draft that allows maintainer edits, with exactly this scope. Rust passes `fin_cancels: bool` through `poll_cancel`/`poll_withdrawn`/`until_withdrawn`/`resolve`, and `serve_track_status_stream` passes `false`. JS `RequestStream` takes `{ finCancels }`. Review it, mark it ready, and land it. Push the doc fix below onto it, or land it as a follow-up commit. -- #7423 asked that a TRACK_INFO behind a publisher refusing TRACK_STATUS fall back to subscribing: - - ✅ Won't fix + doc fix: publishers must answer TRACK_STATUS. moqxr should implement it, which the maintainer called "really not hard". This matches the 2026-10-29 rejection of blind subscribing on [moq-dev/moq#7187](https://github.com/moq-dev/moq/pull/7187). - - Fallback subscribe - - Keep open, defer -- Doc: `doc/concept/standard.md:31` ends with "a reader whose publisher refuses `TRACK_STATUS` as `NOT_SUPPORTED` still subscribes". That is left over from the fallback that [moq-dev/moq#5991](https://github.com/moq-dev/moq/pull/5991) removed. Reword it so only a subscribing reader still subscribes, while a query-only or fetch-only reader fails, as `a_refused_track_status_never_subscribes` (`rs/moq-net/src/ietf/subscriber.rs`) pins. -- Not here: moqx's GROUP_ORDER parameter in TRACK_STATUS_OK, which draft 18 refuses. That is upstream moxygen's fix, facebookexperimental/moxygen#264, tracked by [Moxygen pin bump](/quest/m1/moxygen-pin-bump.md). - -Public API: none. Wire: a draft-18 TRACK_STATUS is no longer withdrawn by a FIN alone. `release` refuses TRACK_STATUS, so nothing needs backporting. - -## Closes - -- [#7438](https://github.com/moq-dev/moq/issues/7438) - draft-18 TRACK_STATUS followed by a FIN is reset instead of answered - -## Related - -- [Moxygen pin bump](/quest/m1/moxygen-pin-bump.md) - the other half of playing through moqx on draft 18 diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index 03ad691880e..b9ad12403b9 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -980,13 +980,15 @@ impl Publisher { self.poll_peer(waiter).map(|peer| self.excluding(&peer)) } - /// Resolve a request's broadcast while the peer still wants the answer. + /// Resolve a request's broadcast while the peer still wants the answer, a FIN withdrawing it + /// where `fin_cancels`. async fn resolve( &self, stream: &mut Stream, + fin_cancels: bool, path: &crate::Path, ) -> Result, Error> { - let mut resolve = Resolve::new(self.session.clone(), path.clone()); + let mut resolve = Resolve::new(self.session.clone(), path.clone(), fin_cancels); kio::wait(|waiter| resolve.poll(waiter, self, stream)).await } @@ -1328,7 +1330,11 @@ impl Publisher { let verdict = gate.verify(token, Some(slot.clone())); // The subscriber cancelling or the session closing withdraws the token. let verified = self - .until_withdrawn(&mut stream, |waiter| verdict.poll_grant(waiter)) + .until_withdrawn( + &mut stream, + super::request_stream::fin_cancels(self.version), + |waiter| verdict.poll_grant(waiter), + ) .await; let Some(verified) = verified else { drop((verdict, slot)); @@ -1374,7 +1380,14 @@ impl Publisher { // We just received a subscribe for this exact namespace, so the peer must have // already seen the announcement. The immediate lookup resolves it at once, or // falls back to the route covering it (an `origin::Requests`), if any. - let broadcast = match self.resolve(&mut stream, &msg.track_namespace).await { + let broadcast = match self + .resolve( + &mut stream, + super::request_stream::fin_cancels(self.version), + &msg.track_namespace, + ) + .await + { Ok(Some(broadcast)) => broadcast, // The reason is the origin's, not ours: a dynamic router refusing on // authorization or a drain says so, and only an unroutable path means the @@ -1620,23 +1633,28 @@ impl Publisher { &self, session: &mut Transport, stream: &mut Stream, + fin_cancels: bool, waiter: &kio::Waiter, ) -> Poll<()> { if session.poll_closed(waiter).is_ready() { return Poll::Ready(()); } - super::request_stream::poll_withdrawn(stream, self.version, waiter) + super::request_stream::poll_withdrawn(stream, fin_cancels, waiter) } /// Poll `step` of a request's setup until ready, or `None` once [`Self::poll_withdrawn`] is. async fn until_withdrawn( &self, stream: &mut Stream, + fin_cancels: bool, mut step: impl FnMut(&kio::Waiter) -> Poll, ) -> Option { let mut session = self.session.clone(); kio::wait(|waiter| { - if self.poll_withdrawn(&mut session, stream, waiter).is_ready() { + if self + .poll_withdrawn(&mut session, stream, fin_cancels, waiter) + .is_ready() + { return Poll::Ready(None); } step(waiter).map(Some) @@ -1677,8 +1695,14 @@ impl Publisher { if let Poll::Ready(res) = marker.poll(waiter, track_serve) { return Poll::Ready(res); } - if super::request_stream::poll_cancel(stream, request_finished, goaways, self.version, waiter).is_ready() - || closed_session.poll_closed(waiter).is_ready() + if super::request_stream::poll_cancel( + stream, + request_finished, + goaways, + super::request_stream::fin_cancels(self.version), + waiter, + ) + .is_ready() || closed_session.poll_closed(waiter).is_ready() { return Poll::Ready(Err(Error::Cancel)); } @@ -1929,7 +1953,9 @@ impl Publisher { msg: &ietf::Subscribe<'_>, ) -> Option> { let declared = self - .until_withdrawn(stream, |waiter| self.peer_setup.poll_get(waiter)) + .until_withdrawn(stream, super::request_stream::fin_cancels(self.version), |waiter| { + self.peer_setup.poll_get(waiter) + }) .await?; // A live SUBSCRIBE's NEW_GROUP_REQUEST asks nothing more: subscribing is itself a join, // which the track's refresh ratio judges. @@ -1956,7 +1982,9 @@ impl Publisher { // anything is served. let subscribing = track.subscribe(subscription.clone()); let mut subscribed = match self - .until_withdrawn(stream, |waiter| subscribing.poll_ok(waiter)) + .until_withdrawn(stream, super::request_stream::fin_cancels(self.version), |waiter| { + subscribing.poll_ok(waiter) + }) .await? { Ok(subscribed) => subscribed, @@ -1966,8 +1994,10 @@ impl Publisher { // A relay's copy that went idle cannot say where its live edge is until its route // answers again; answering from its cache would advertise a stale one. - self.until_withdrawn(stream, |waiter| subscribed.poll_live(waiter)) - .await?; + self.until_withdrawn(stream, super::request_stream::fin_cancels(self.version), |waiter| { + subscribed.poll_live(waiter) + }) + .await?; // The filter and any fill are relative to the live edge, so snapshot it once: the fill // ends exactly where a Next Object subscription begins, which is what lets the draft's @@ -2794,7 +2824,14 @@ impl Publisher { // The peer must have seen the announcement to name this namespace, so this // resolves like a SUBSCRIBE does. - let broadcast = match gate.guard(self.resolve(&mut stream, &namespace)).await { + let broadcast = match gate + .guard(self.resolve( + &mut stream, + super::request_stream::fin_cancels(self.version), + &namespace, + )) + .await + { Ok(Some(broadcast)) => broadcast, Ok(None) => return Ok(()), Err(err) => return self.reject_fetch(stream, &err, &err.to_string()).await, @@ -2907,8 +2944,14 @@ impl Publisher { compression, )); kio::wait(|waiter| { - if super::request_stream::poll_cancel(&mut stream, &mut finished, &mut messages, self.version, waiter) - .is_ready() + if super::request_stream::poll_cancel( + &mut stream, + &mut finished, + &mut messages, + super::request_stream::fin_cancels(self.version), + waiter, + ) + .is_ready() { return Poll::Ready(None); } @@ -3035,8 +3078,14 @@ impl Publisher { let res = { let mut respond = std::pin::pin!(respond); kio::wait(|waiter| { - if super::request_stream::poll_cancel(&mut stream, &mut finished, &mut messages, self.version, waiter) - .is_ready() + if super::request_stream::poll_cancel( + &mut stream, + &mut finished, + &mut messages, + super::request_stream::fin_cancels(self.version), + waiter, + ) + .is_ready() { return Poll::Ready(None); } @@ -3094,7 +3143,15 @@ impl Publisher { let mut deadline = crate::time::Deadline::after(&self.runtime, Duration::from_secs(10)); kio::wait(|waiter| { // The request reader is what the subscriber FINs or resets. - if super::request_stream::poll_cancel(stream, finished, messages, self.version, waiter).is_ready() { + if super::request_stream::poll_cancel( + stream, + finished, + messages, + super::request_stream::fin_cancels(self.version), + waiter, + ) + .is_ready() + { return Poll::Ready(Err(Error::Cancel)); } let joins = self.joins.poll(waiter, |joins| match joins.get(&subscribe_id) { @@ -3171,7 +3228,13 @@ impl Publisher { if !gate.allows() { return self.reject_track_status(stream, &Error::Unauthorized).await; } - let broadcast = match gate.guard(self.resolve(&mut stream, &msg.track_namespace)).await { + // Nothing can follow a TRACK_STATUS, so a FIN only ends the requester's input; a reset or + // STOP_SENDING withdraws it. + let fin_cancels = false; + let broadcast = match gate + .guard(self.resolve(&mut stream, fin_cancels, &msg.track_namespace)) + .await + { Ok(Some(broadcast)) => broadcast, Ok(None) => return Ok(()), Err(err) => return self.reject_track_status(stream, &err).await, @@ -3188,7 +3251,7 @@ impl Publisher { let mut finished = false; let mut messages = super::request_stream::Messages::new(self.session.clone(), self.control.client()); kio::wait(|waiter| { - if super::request_stream::poll_cancel(&mut stream, &mut finished, &mut messages, self.version, waiter) + if super::request_stream::poll_cancel(&mut stream, &mut finished, &mut messages, fin_cancels, waiter) .is_ready() { return Poll::Ready(None); @@ -4294,16 +4357,18 @@ struct LiveGroup { /// requester withdraws or the session closes. struct Resolve { session: Transport, + fin_cancels: bool, path: crate::Path, state: ResolveState, } #[kio::machine(self.state: ResolveState)] impl Resolve { - fn new(session: Transport, path: crate::Path) -> Self { + fn new(session: Transport, path: crate::Path, fin_cancels: bool) -> Self { Self { session, path, + fin_cancels, state: ResolveState::Start, } } @@ -4314,7 +4379,7 @@ impl Resolve { publisher: &Publisher, stream: &mut Stream, ) -> Poll, Error>> { - let origin = wait!(Origin => match publisher.poll_withdrawn(&mut self.session, stream, waiter) { + let origin = wait!(Origin => match publisher.poll_withdrawn(&mut self.session, stream, self.fin_cancels, waiter) { Poll::Ready(()) => Poll::Ready(None), Poll::Pending => publisher.poll_serving_origin(waiter).map(Some), }); @@ -4323,7 +4388,7 @@ impl Resolve { }; // The immediate lookup: answering a peer never starts discovery of its own. let requesting: kio::Pending = origin.lookup(self.path.clone(), None); - let found = wait!(Lookup => match publisher.poll_withdrawn(&mut self.session, stream, waiter) { + let found = wait!(Lookup => match publisher.poll_withdrawn(&mut self.session, stream, self.fin_cancels, waiter) { Poll::Ready(()) => Poll::Ready(None), Poll::Pending => requesting.poll_ok(waiter).map(Some), }); @@ -6892,7 +6957,7 @@ mod serve_tests { &mut stream, &mut finished, &mut goaways, - version, + super::super::request_stream::fin_cancels(version), waiter ), Poll::Ready(Err(Error::ProtocolViolation)) @@ -8516,6 +8581,52 @@ mod serve_tests { body } + /// A requester may FIN right after TRACK_STATUS, since nothing can follow it (moxygen + /// does). That ends its input and is still answered, on draft 18 too. + #[kio::test] + async fn track_status_finished_at_once_is_answered() { + for version in ALL_VERSIONS { + let h = serve_session( + version, + track::Info::timed(), + crate::origin::Route::default(), + ScriptedSession::per_stream_eof(vec![Vec::new()]), + ); + let stream = Stream::open(&mut crate::driver::Transport::new(h.session.clone()), version) + .await + .unwrap(); + let mark = h.log.trail().len(); + let body = track_status("room", true, version); + let task = h + .publisher + .clone() + .handle_stream(ietf::TrackStatus::ID, ietf::Body(bytes::Bytes::from(body)), stream) + .unwrap(); + kio::clock::timeout(std::time::Duration::from_secs(1), task) + .await + .unwrap_or_else(|_| panic!("{version}: never answered")); + + let trail = h.log.trail()[mark..].to_vec(); + let wire: Vec = trail + .iter() + .filter_map(|(_, sent)| match sent { + Sent::Write(bytes) => Some(bytes.clone()), + _ => None, + }) + .flatten() + .collect(); + assert!(!wire.is_empty(), "{version}: not answered"); + let mut buf = Decoder::new(&wire, version.into()); + assert_eq!(buf.varint().unwrap(), ietf::TrackStatusOk::ID, "{version}"); + ietf::TrackStatusOk::decode(&mut buf, version).unwrap(); + assert!( + matches!(trail.last(), Some((_, Sent::Finish))), + "{version}: the answer did not end with a FIN: {trail:?}" + ); + assert!(h.log.resets().is_empty(), "{version}: reset"); + } + } + /// TRACK_STATUS gets what a SUBSCRIBE_OK would carry, as far as each draft's answer has /// room, without subscribing to the track. INCLUDE_PROPERTIES=0 empties the properties. #[kio::test] @@ -12065,7 +12176,11 @@ mod serve_tests { ); assert_eq!(demanded(), !matches!(setup, Setup::Resolving), "{version} {setup:?}"); - withdraw(&request, version); + match kind { + // A FIN only ends a TRACK_STATUS requester's input; a reset withdraws it. + request::Kind::TrackStatus => request.close(crate::lite::test_transport::Close::Reset), + _ => withdraw(&request, version), + } let res = kio::clock::timeout(std::time::Duration::from_secs(1), serving) .await .unwrap_or_else(|_| panic!("{version} {setup:?}: outlived its withdrawal")); diff --git a/rs/moq-net/src/ietf/request_stream.rs b/rs/moq-net/src/ietf/request_stream.rs index 89ee8c0d369..ac39ce7094a 100644 --- a/rs/moq-net/src/ietf/request_stream.rs +++ b/rs/moq-net/src/ietf/request_stream.rs @@ -8,21 +8,28 @@ use crate::{ coding::{Decode, DecodeError, Decoder, Stream, Writer}, }; +/// Whether the requester finishing its messages withdraws a request on `version`. +/// +/// Draft 18 asks for a reset or STOP_SENDING (section 3.3.2) and names a FIN as a cancel only for +/// SUBSCRIBE_NAMESPACE and SUBSCRIBE_TRACKS (section 6.1), but our own draft-18 requesters cancel +/// by FIN, so we read one that way. TRACK_STATUS passes `false` instead: nothing can follow it, so +/// a requester may FIN right after it (moxygen does). pub(super) fn fin_cancels(version: Version) -> bool { matches!(version, Version::Draft18) } -/// Watch abrupt cancellation after the requester has finished sending messages. +/// Watch abrupt cancellation after the requester has finished sending messages, and its FIN +/// where `fin_cancels`. pub(super) fn poll_cancel( stream: &mut Stream, finished: &mut bool, messages: &mut Messages, - version: Version, + fin_cancels: bool, waiter: &kio::Waiter, ) -> Poll> { if !*finished { match messages.poll_end(&mut stream.reader, waiter) { - Poll::Ready(Ok(())) if !fin_cancels(version) => *finished = true, + Poll::Ready(Ok(())) if !fin_cancels => *finished = true, Poll::Ready(result) => return Poll::Ready(result), Poll::Pending => {} } @@ -33,17 +40,18 @@ pub(super) fn poll_cancel( /// Watch for the requester ending a request it has not been answered on yet, without consuming /// what it sent meanwhile: a waiting message (an update, say) ends the watch on the reader and /// is read once the request is answered. A withdrawal queued behind an update is therefore seen -/// only then; until the verifier answers, the requester holds nothing but its own slot. +/// only then; until the verifier answers, the requester holds nothing but its own slot. A FIN +/// withdraws it only where `fin_cancels`. pub(super) fn poll_withdrawn( stream: &mut Stream, - version: Version, + fin_cancels: bool, waiter: &kio::Waiter, ) -> Poll<()> { if stream.writer.poll_closed(waiter).is_ready() { return Poll::Ready(()); } match stream.reader.poll_has_more(waiter) { - Poll::Ready(Ok(false)) if fin_cancels(version) => Poll::Ready(()), + Poll::Ready(Ok(false)) if fin_cancels => Poll::Ready(()), Poll::Ready(Err(_)) => Poll::Ready(()), _ => Poll::Pending, } @@ -489,7 +497,7 @@ mod tests { &mut stream, &mut finished, &mut messages, - version, + fin_cancels(version), waiter, ))) .is_pending(), @@ -503,7 +511,7 @@ mod tests { &mut stream, &mut finished, &mut messages, - version, + fin_cancels(version), waiter, ))), Poll::Ready(Err(Error::ProtocolViolation)) diff --git a/rs/moq-net/src/ietf/subscriber.rs b/rs/moq-net/src/ietf/subscriber.rs index 4f9e02231c5..8dfecd0ffc4 100644 --- a/rs/moq-net/src/ietf/subscriber.rs +++ b/rs/moq-net/src/ietf/subscriber.rs @@ -1873,7 +1873,12 @@ impl Subscriber { let version = self.version; let verified = kio::wait(|waiter| { if session.poll_closed(waiter).is_ready() - || super::request_stream::poll_withdrawn(&mut stream, version, waiter).is_ready() + || super::request_stream::poll_withdrawn( + &mut stream, + super::request_stream::fin_cancels(version), + waiter, + ) + .is_ready() { return Poll::Ready(None); }