diff --git a/doc/bin/relay/config.md b/doc/bin/relay/config.md index 11b228cdd29..3fbad7106fc 100644 --- a/doc/bin/relay/config.md +++ b/doc/bin/relay/config.md @@ -109,21 +109,19 @@ read, whether or not their message is complete. ## \[session] and \[peer] -Request caps apply separately to each session on every transport. The relay +Session limits apply separately to each session on every transport. The relay uses `[peer]` for an admitted grant marked `peer` or `upstream`, including verified LAN membership, and for links it dials through the cluster. A client -certificate, route hop, or cluster-looking URL alone does not select peer caps. +certificate, route hop, or cluster-looking URL alone does not select peer limits. ```toml [session] announces = 1000 # Simultaneous broadcasts or namespaces. -subscriptions = 1000 # Simultaneously held subscriptions. -fetches = 10000 # Independent simultaneous FETCH requests. +requests = 10000 # Other simultaneous moq-transport requests. [peer] announces = 100000 -subscriptions = 10000 -fetches = 10000 +requests = 20000 [peer.quic] max_streams = 100000 # Concurrent QUIC streams per direction. @@ -139,15 +137,17 @@ not throttled by `[quic]` limits sized for one viewer, for example `--peer-quic-max-streams=200000`. Peers over WebSocket, TCP, or iroh keep their transport's own limits. -These are the defaults. For example, `--peer-subscriptions=50000` raises the -subscription cap on cluster links. `--session-fetches` and `--peer-fetches` -set the independent FETCH caps; concurrent callers of the same group each -hold a slot. Size peer caps for the combined traffic they carry, and use -session peak counters to check announcement and subscription headroom. -Exceeding a cap closes the session with `TOO_MANY_REQUESTS`; reconnecting with -the same load will exceed it again. Zero admits no entries of that kind, not unlimited -entries. On moq-transport drafts 14 to 16 these caps also size the request -window, so very small values can prevent other requests from progressing. +These are the defaults. Each subscription and FETCH holds a stream on moq-lite +and on moq-transport draft 17 and later, so `[quic]` or `[peer.quic]` +`max_streams` bounds them there, and a peer past it waits rather than fails. +On drafts 14 to 16, `announces` and `requests` together size the request +window instead, which every request counts against, so very small values can +prevent other requests from progressing. On later drafts `requests` bounds the +PUBLISHes a peer's track listings hold; the rest are skipped. Size peer limits +for the combined traffic they carry, and use session peak counters to check +announcement and subscription headroom. Exceeding `announces` closes the session +with `TOO_MANY_REQUESTS`; reconnecting with the same load will exceed it again. +Zero admits no entries of that kind, not unlimited entries. ## \[runtime] diff --git a/doc/concept/stats.md b/doc/concept/stats.md index d5a2497ec8d..affc0ed9ae0 100644 --- a/doc/concept/stats.md +++ b/doc/concept/stats.md @@ -368,9 +368,10 @@ reads it as zero when absent. A request moved to another tier stays counted wher it was admitted; later traffic follows the new tier. `announces_peak` and `subscriptions_peak` are the most broadcasts announced to -the relay, and subscriptions held on it, by any one session. Compare them with -the relay's [client or peer session limits](/bin/relay/config#session-and-peer): -a session that goes past one is closed with `TOO_MANY_REQUESTS`. On +the relay, and subscriptions held on it, by any one session. Compare announces +with the relay's [client or peer session limits](/bin/relay/config#session-and-peer), +past which a session is closed with `TOO_MANY_REQUESTS`, and subscriptions with +its QUIC `max_streams`, which bounds them. On `sessions.json` a peak never goes down while the label has a session; on the totals and presence tracks it never goes down while the track lives. Summing nodes or labels takes the largest. diff --git a/doc/lib/rs/moq-net.md b/doc/lib/rs/moq-net.md index d9295f9ad4a..28b880e9eb4 100644 --- a/doc/lib/rs/moq-net.md +++ b/doc/lib/rs/moq-net.md @@ -25,7 +25,7 @@ What you use it for, beyond what the concept page already describes: - **Publish only while someone is watching.** `demand()` on a track, group, or broadcast says whether a subscriber is attached, which is how capture and transcode skip work nobody asked for. Holding a broadcast or track consumer is not demand: a track consumer requests nothing until it queries, subscribes, or fetches, and those count until dropped. A shared fetch stays up until its last reader leaves. - **Use the model without a runtime.** Disable default features on `moq-net` to use its `poll_*` APIs and origin driver with caller-supplied time. The default `async` feature adds async helpers, `time::run`, and both wire sessions. - **You drive the session, or `moq-tokio` does.** `connect` and `accept` return a session plus a driver that never reads the clock itself. `moq_net::time::run` polls it on tokio or in the browser. `moq-tokio` and `moq-wasm` hide that. A custom transport implements `moq_net::transport::poll`, and `moq_net::transport::memory::pair` links two sessions in one process with no sockets, for tests or in-process links. -- **A session caps what its peer can hold.** `session::Limits` (via `Client::with_limits` and `Server::with_limits`) bounds announces, subscriptions, and FETCH requests independently per session; the defaults suit a relay mesh, so lower them for untrusted peers. Past a cap, the session closes with `TOO_MANY_REQUESTS`. On moq-transport drafts 14 to 16 they also size the request-ID window, which every request counts against, so very low limits can starve it. Peer-declared lengths are capped before they are buffered. +- **A session bounds what its peer can hold.** Each moq-lite request, and each moq-transport request from draft 17 on, holds a stream, so the transport's stream credit bounds subscriptions and FETCHes. `session::Limits` (via `Client::with_limits` and `Server::with_limits`) bounds the rest per session: `announces`, and `requests`, which with `announces` sizes the request-ID window on moq-transport drafts 14 to 16. The defaults suit a relay mesh, so lower them for untrusted peers. Past a limit, the session closes with `TOO_MANY_REQUESTS`; very low limits can starve the window, which every request counts against. Peer-declared lengths are capped before they are buffered. - **Authorization is in band.** On moq-lite 07 (`moq-lite-07-wip`, opt-in) and on moq-transport draft-17+ with the [MoQ Auth extension](/draft/moq-auth), `session.auth()` presents tokens without reconnecting and watches the grant the peer sent back. A server verifies tokens itself by taking `handshake.auth().requests()` before `ok()`. `authorize(&grant)` narrows or widens a live session on any version: what falls outside resets with `Unauthorized` and the session stays up. A client that publishes outside its grant closes the session, naming the path. - **A graceful close waits.** `session.close().await` withdraws announcements and drains for up to one second. Application delivery requires explicit `moq-lite-07-wip`; older Lite versions (including default lite-06) and IETF wait only for transport ACKs. `abort` ends immediately. IETF drafts 14 through 16 send withdrawals without waiting. diff --git a/js/net/src/ietf/setup_options.ts b/js/net/src/ietf/setup_options.ts index f8879de4b82..4a18859c80e 100644 --- a/js/net/src/ietf/setup_options.ts +++ b/js/net/src/ietf/setup_options.ts @@ -34,8 +34,8 @@ const KNOWN_SETUP_OPTIONS: readonly bigint[] = Object.values(SetupOption); /** * Requests a draft-14 to -16 peer may hold open at once. * - * Sized like moq-net's window: twice its default 100,000 announce and 10,000 - * subscription and FETCH caps. Draft-17 dropped MAX_REQUEST_ID. Grants are batched per + * Sized like moq-net's window: twice its default 100,000 announces and 20,000 + * other requests. Draft-17 dropped MAX_REQUEST_ID. Grants are batched per * half window, so only about half of it is guaranteed to a peer holding requests open. */ export const REQUEST_WINDOW = 240_000n; diff --git a/js/net/src/util/limits.ts b/js/net/src/util/limits.ts index 7c6cb6ec52b..904a412edc1 100644 --- a/js/net/src/util/limits.ts +++ b/js/net/src/util/limits.ts @@ -1,6 +1,10 @@ import { Session, SessionCode } from "../error.ts"; -/** How many live requests a peer may hold on one session, as moq-net's `session::Limits`. @internal */ +/** + * How many live requests a peer may hold on one session. Unlike moq-net's `session::Limits`, it + * still caps subscriptions and FETCHes: `@moq/qmux` returns stream credit on accept, not on close, + * so credit alone does not bound them here. @internal + */ export interface Limits { /** Broadcasts (moq-lite) or namespaces (moq-transport) the peer may have announced to us. */ announces: number; @@ -10,7 +14,7 @@ export interface Limits { fetches: number; } -/** moq-net's default limits. @internal */ +/** The default limits, matching moq-net's announces. @internal */ export const LIMITS: Readonly = Object.freeze({ announces: 100_000, subscriptions: 10_000, fetches: 10_000 }); /** A session's count of live peer requests, which closes the session past its cap. @internal */ diff --git a/quest/m1/api-audit/README.md b/quest/m1/api-audit/README.md index c8f31b933e8..b305cc59ddf 100644 --- a/quest/m1/api-audit/README.md +++ b/quest/m1/api-audit/README.md @@ -75,7 +75,6 @@ Rejected in planning: - [Binding connection state](/quest/m1/api-audit/binding-state.md) - one `state()` snapshot and `state_changed()` replace `status`, `connects`, and both `failure` polls - [moq-net exports with a consumer](/quest/m1/api-audit/net-exports.md) - Rust and JS model exports without a consumer go private, wrong ones are deleted, and JS names mirror Rust - [One clean close](/quest/m1/api-audit/clean-close.md) - a clean session close has one spelling and failures are recorded inside moq-net -- [Session limits only where needed](/quest/m1/api-audit/session-limits.md) - `session::Limits` keeps only bounds that nothing else enforces, and its documented example compiles - [Ranges refuse what the wire drops](/quest/m1/api-audit/ranges-wire.md) - relative and time anchors fail loud where a wire cannot carry them, `floor()` honors the subscription, and bindings take an optional max delay - [Derived origins borrow](/quest/m1/api-audit/derived-origin-close.md) - closing a JS `scope()` or `withPreference()` handle releases only that handle - [Wrapper config names](/quest/m1/api-audit/wrapper-config.md) - Python, Go, and Dart client options use the FFI's names and nesting diff --git a/quest/m1/api-audit/session-limits.md b/quest/m1/api-audit/session-limits.md deleted file mode 100644 index 56a0e39dfbc..00000000000 --- a/quest/m1/api-audit/session-limits.md +++ /dev/null @@ -1,30 +0,0 @@ -# [S] Session limits only where needed - -## Goal - -`moq_net::session::Limits` keeps only the bounds nothing else enforces. A -count that QUIC stream credit or the moq-transport request window already -bounds is not also a runtime refusal cap, and the documented example -compiles. - -## Plan - -Decided 2026-10-22 (API audit). `session.rs` `Limits` with three -`with_limits` builders (client, server, server request) caps subscriptions -and fetches, which AGENTS.md's rule against constants that only refuse at -runtime forbids where flow control already bounds the cost. The -`MIGRATE.md` example does not compile because the struct is -`#[non_exhaustive]`. - -This revisits part of the per-session request caps from #4820 (the m0 DoS -review), so prove each removal first: - -- For each cap, show which existing bound covers it on each version: lite - streams consume QUIC stream credit; drafts 14 to 16 have the request - window; later drafts have MAX_REQUEST_ID. Drop `subscriptions` and - `fetches` where covered, with a test that the peer is still bounded. -- Keep the bounds with no other limit, such as lite announces and the - drafts 14 to 16 request window. -- Fix the example (a constructor or `Default` plus field updates). - -Public API: moq-net `Limits` fields removed. Wire: none. diff --git a/quest/m1/js-qmux-credit.md b/quest/m1/js-qmux-credit.md index c9448579696..64ad8b2bed1 100644 --- a/quest/m1/js-qmux-credit.md +++ b/quest/m1/js-qmux-credit.md @@ -12,12 +12,8 @@ mirror Rust. `maybeReplenishStreamCredit` in `js/qmux/src/session.ts` fires once a stream is accepted and its receive half is terminal. A bidirectional subscription whose receive half ends while its send half stays open frees credit early. -Because of this, [Session limits](/quest/m1/api-audit/session-limits.md) +Because of this, [moq-dev/moq#6467](https://github.com/moq-dev/moq/pull/6467) kept the `@moq/net` caps. Fix the credit, then remove those caps, with a test that a half-closed stream still holds its credit. Public API: `@moq/net` loses its subscription and FETCH caps. Wire: none. - -## Related - -- [Session limits](/quest/m1/api-audit/session-limits.md) - kept the JS caps because of this diff --git a/quest/m1/listing-credit.md b/quest/m1/listing-credit.md index 254c36d0a3c..f2803ab4cde 100644 --- a/quest/m1/listing-credit.md +++ b/quest/m1/listing-credit.md @@ -13,7 +13,7 @@ In `rs/moq-net/src/ietf/publisher/tracks.rs`, every FORWARD=1 or unfittable track goes into `request.skips` as the listing is enumerated, and `poll_write_skips` paces only the writes. A peer that stops reading makes the session hold state proportional to the whole catalog, multiplied across -peers. After [Session limits](/quest/m1/api-audit/session-limits.md), the +peers. After [moq-dev/moq#6467](https://github.com/moq-dev/moq/pull/6467), the listing PUBLISHes are bounded only by `Limits::requests`, a runtime cap. Decided 2026-10-23 (maintainer): replace the cap with flow control. Couple @@ -22,7 +22,3 @@ it, and drop the listing's use of `Limits::requests`. Test with a peer that withholds credit and reads nothing. Public API: none expected. Wire: none. - -## Required - -- [Session limits](/quest/m1/api-audit/session-limits.md) - rewrites the same listing code diff --git a/quest/m2/ietf-join-after-finish.md b/quest/m2/ietf-join-after-finish.md index 7996a56151c..7c9f790a5b9 100644 --- a/quest/m2/ietf-join-after-finish.md +++ b/quest/m2/ietf-join-after-finish.md @@ -47,16 +47,18 @@ alive, so retaining it costs memory a peer controls. Candidate bounds: stream; keep the entry until the subscriber closes its side, with our subscriber holding it open until its joining FETCH resolves. Drafts 14 to 16 share the control stream and have no such signal. -- **The subscription limit.** A finished entry stays charged to the peer's - `session::Limits::subscriptions`, released when its FETCH takes it, the peer - cancels, or a new subscription needs the room (oldest finished entry first). - This works on every draft, and a peer that never sends the FETCH costs no - more than an open subscription. +- **The request window.** On drafts 14 to 16 a finished entry keeps its + SUBSCRIBE's request permit, so it counts against the window that + `session::Limits` sizes, released when its FETCH takes it, the peer + cancels, or a new request needs the room (oldest finished entry first). A + peer that never sends the FETCH costs no more than an open subscription. + There is no per-session subscription limit to charge instead: stream credit + bounds subscriptions on later drafts. - **The session alone.** Grows with every subscription a long-lived relay session ever makes, so probably not bounded enough. -Recommendation: the subscription limit, plus the request close where the -draft has one. Keep only entries that can be answered (`Joined::Group`); an +Recommendation: the request close where the draft has one, and the request +window on drafts 14 to 16. Keep only entries that can be answered (`Joined::Group`); an unsubscribed or refused subscription still drops its entry at once. The entry must not outlive what authorized the subscription: when its request token's grant expires or is revoked, or the session grant no longer covers diff --git a/rs/moq-net/MIGRATE.md b/rs/moq-net/MIGRATE.md index d3185409596..500bfb6e0ba 100644 --- a/rs/moq-net/MIGRATE.md +++ b/rs/moq-net/MIGRATE.md @@ -434,11 +434,14 @@ Treat both like `NotFound` if you match on errors. ### Sessions cap peer requests (#4820) -A peer past the session's announce, subscription, or fetch bound loses the session with `TooManyRequests`. +A peer past the session's announce bound loses the session with `TooManyRequests`. +Stream credit bounds its subscriptions and FETCHes, except on moq-transport drafts 14 to 16, where the request window sized by `announces` and `requests` does. Raise the defaults for a large relay mesh. ```rust -let client = Client::new().with_limits(session::Limits { subscriptions: 100_000, ..Default::default() }); +let mut limits = session::Limits::default(); +limits.announces = 1_000_000; +let client = Client::new().with_limits(limits); ``` ### A path is one broadcast (#4741) diff --git a/rs/moq-net/src/auth.rs b/rs/moq-net/src/auth.rs index baada202eb6..e0c3ebb60f4 100644 --- a/rs/moq-net/src/auth.rs +++ b/rs/moq-net/src/auth.rs @@ -1113,9 +1113,9 @@ impl Issue { } } -/// A request's slot against the session's cap, shared with the application's verification -/// of its token so work still in flight stays counted after the request ends. Opaque here: -/// auth only keeps it alive. +/// A request's slot in the session's count, shared with the application's verification of its +/// token so work still in flight stays counted after the request ends. Opaque here: auth only +/// keeps it alive. pub(crate) type Hold = std::sync::Arc; /// The serving task's hold on one peer token's [`Issue`]. diff --git a/rs/moq-net/src/client.rs b/rs/moq-net/src/client.rs index 90c851323c7..19ce7c71dd5 100644 --- a/rs/moq-net/src/client.rs +++ b/rs/moq-net/src/client.rs @@ -388,7 +388,7 @@ impl Client { // The server's requests, admitted up to our limits and granted back as they close. parameters.set_varint( ietf::ParameterVarInt::MaxRequestId, - ietf::initial_max_request_id(self.limits.requests(), false), + ietf::initial_max_request_id(self.limits.window(), false), ); parameters.set_bytes(ietf::ParameterBytes::Implementation, b"moq-lite-rs".to_vec()); // Advertise the request path in-band (draft 14-16), same as the lite-05 SETUP. diff --git a/rs/moq-net/src/error.rs b/rs/moq-net/src/error.rs index cf300d9e851..9cb5a3af531 100644 --- a/rs/moq-net/src/error.rs +++ b/rs/moq-net/src/error.rs @@ -38,9 +38,9 @@ pub enum SessionError { #[error("key-value formatting error")] KeyValueFormatting, - /// The peer went past what the session allows: a request ID at or past the - /// MAX_REQUEST_ID we advertised (moq-transport drafts 14 to 16), or more announcements, - /// subscriptions, or FETCH requests than its `crate::session::Limits`. + /// The peer went past what the session allows: more announcements than its + /// `crate::session::Limits`, or on moq-transport drafts 14 to 16, a request ID at or past + /// the MAX_REQUEST_ID we advertised or more live requests than the window. #[error("too many requests")] TooManyRequests, @@ -451,8 +451,8 @@ pub enum Error { #[error("too many parameters")] TooManyParameters, - /// The peer already holds as many FETCH requests, announcements, or subscriptions as this - /// session allows (see `crate::session::Limits`). + /// The peer went past this session's `crate::session::Limits`: too many announcements, or + /// too many requests on moq-transport drafts 14 to 16. #[error("too many requests")] TooManyRequests, diff --git a/rs/moq-net/src/ietf/control.rs b/rs/moq-net/src/ietf/control.rs index a65f54cc712..e83e0591efc 100644 --- a/rs/moq-net/src/ietf/control.rs +++ b/rs/moq-net/src/ietf/control.rs @@ -136,7 +136,7 @@ impl Control { incoming: None, // The peer takes the other parity: a client's IDs are even, a server's odd. modern: Spent::new(u64::from(client)), - history: crate::session::Limits::default().requests(), + history: crate::session::Limits::default().window(), going_away: false, }), } @@ -484,7 +484,7 @@ mod tests { /// Skipping to the top of a production-sized window records one run, not every ID. #[test] fn draft16_a_jump_is_one_run_split_only_by_requests_inside_it() { - let window = crate::session::Limits::default().requests(); + let window = crate::session::Limits::default().window(); let control = Control::new(None, false).with_window(window, false, Version::Draft16); let top = 2 * (window - 1); let runs = |control: &Control| { diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index 236c20a38a8..4996a1defb2 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -695,9 +695,8 @@ pub(super) struct Publisher { auth: crate::auth::Handle, // Dispatched finite serves, including those not yet polled. pub(super) owed: Arc, - // Subscriptions the peer may hold at once (`session::Limits::subscriptions`). + // Subscriptions the peer holds, PUBLISHes for its listings capped by `session::Limits::requests`. pub(super) subscriptions: crate::session::Slots, - pub(super) fetches: crate::session::Slots, // Ranks every subscription's group streams against each other for the transport. priority: PriorityQueue, // The peer's SUBSCRIBE_TRACKS requests and the PUBLISHes they made. @@ -779,7 +778,6 @@ impl Publisher { auth: crate::auth::Handle::new(false), owed: Default::default(), subscriptions: Default::default(), - fetches: Default::default(), priority: Default::default(), listings: Default::default(), } @@ -1190,18 +1188,13 @@ impl Publisher { ) .await; } - // Held for the life of the subscription, and while the application verifies its - // token. A peer past its limits loses the session. - let slot: crate::auth::Hold = match self.subscriptions.acquire() { - Ok(slot) => std::sync::Arc::new(slot), - Err(err) => { - self.session.clone().close( - super::error::to_session_code(&crate::SessionError::from(&err)), - "too many subscriptions", - ); - return Err(err); - } - }; + // Held for the life of the subscription, and by every token verification the + // application takes for it, initial or renewal, even past a cancel. The request keeps + // its stream, and so its stream credit or request window slot, until all of them let + // go, so a peer cancelling and resubscribing cannot leave more verifications in flight + // than its credit admits. + let credit = kio::Producer::<()>::default(); + let slot: crate::auth::Hold = std::sync::Arc::new((self.subscriptions.hold(), credit.consume())); let mut request_finished = false; let mut goaways = super::request_stream::Messages::new(self.session.clone(), self.control.client()); @@ -1225,6 +1218,8 @@ impl Publisher { }) .await; let Some(verified) = verified else { + drop((verdict, slot)); + self.released(&credit).await; return Ok(()); }; let admitted = crate::auth::RequestGrant::new( @@ -1501,6 +1496,8 @@ impl Publisher { }; // A FETCH joining this subscription ends with it, before the peer reads a word. drop(_join); + // The subscription's demand is gone; only its credit may still wait on a verification. + drop((request_grant, _slot)); let (served, streams) = match subscribed { Ok(Ok(Subscribed::Served(served, streams))) => (served, streams), @@ -1517,10 +1514,23 @@ impl Publisher { } }, }; - self.write_publish_done(stream, request_id, served, streams).await + self.write_publish_done(stream, request_id, served, streams, Some(&credit)) + .await } } + /// Wait until no token verification holds `credit`'s request any more, or the session closes. + async fn released(&self, credit: &kio::Producer<()>) { + let mut session = self.session.clone(); + kio::wait(|waiter| { + if session.poll_closed(&mut waiter.context()).is_ready() || credit.poll_unused(waiter).is_ready() { + return Poll::Ready(()); + } + Poll::Pending + }) + .await + } + /// Send the END_OF_TRACK a subscription that ran to the track's end still owes: draft-14 /// on carries no end location in PUBLISH_DONE, so the marker is what tells the subscriber /// where the track ended. One cancelled while the marker waits for stream credit abandons @@ -1558,13 +1568,15 @@ impl Publisher { } /// End a subscription on the wire with the PUBLISH_DONE `served` reports, after `streams` - /// group streams, returning how serving ended. + /// group streams, returning how serving ended. The stream closes only once no verification + /// holds `credit`'s request, if it has one. async fn write_publish_done( &self, mut stream: Stream, request_id: RequestId, served: Served, streams: u64, + credit: Option<&kio::Producer<()>>, ) -> Result<(), Error> { let (status, reason) = served.status(self.version); let res = match served { @@ -1587,6 +1599,11 @@ impl Publisher { }) .await; + // The peer learns the subscription ended at once, but the stream holds its credit until + // the application lets go of every token it took for it. + if let Some(credit) = credit { + self.released(credit).await; + } // PUBLISH_DONE is the last thing on this stream, so it needs the acknowledgement too. let _ = stream.writer.close().await; @@ -2507,16 +2524,6 @@ impl Publisher { msg: ietf::Fetch<'_>, admission: FetchGate, ) -> Result<(), Error> { - let _slot = match self.fetches.acquire() { - Ok(slot) => slot, - Err(err) => { - self.session.close( - super::error::to_session_code(&crate::SessionError::from(&err)), - "too many fetches", - ); - return Err(err); - } - }; let namespace = match &msg.fetch_type { FetchType::Standalone { namespace, .. } | FetchType::Filtered { namespace, .. } => Some(namespace), _ => None, @@ -9259,35 +9266,6 @@ mod serve_tests { } } - /// A SUBSCRIBE past the session's cap closes the session with TOO_MANY_REQUESTS. - #[moq_clock::test] - async fn subscriptions_past_the_cap_close_the_session() { - for version in [Version::Draft14, Version::Draft16, Version::Draft20] { - let mut h = serve(version); - h.publisher.subscriptions = crate::session::Slots::new(0); - let stream = Stream::open(&mut crate::driver::Transport::new(h.session.clone()), version) - .await - .unwrap(); - let mut body = Vec::new(); - subscribe(Filter::NextObject, None) - .encode_msg(&mut Encoder::new(&mut body, version.into()), version) - .unwrap(); - h.publisher - .clone() - .handle_stream(ietf::Subscribe::ID, ietf::Body(body.into()), stream, false) - .unwrap_or_else(|e| panic!("{version}: the request was not started: {e}")) - .await; - assert_eq!( - h.log.closes(), - vec![( - crate::SessionError::TooManyRequests.to_code(), - "too many subscriptions".to_string() - )], - "{version}" - ); - } - } - /// Legal requests we don't serve are refused NOT_SUPPORTED one at a time, and the /// session stays open for the next one. #[moq_clock::test] @@ -13055,54 +13033,92 @@ mod serve_tests { } /// A peer that ends the subscription while a renewal is still being verified ends it here - /// too: with a grant that never expires and an acceptor that never answers the renewal, - /// only the stream closing can end the request, and it must. + /// too: with a grant that never expires and an acceptor sitting on the renewal, the stream + /// closing drops the subscription's demand at once. The request keeps its stream, and so its + /// credit, until the acceptor lets go of the renewal. #[moq_clock::test] async fn a_closed_subscription_ends_while_a_renewal_is_pending() { const VERSION: Version = Version::Draft18; - let (auth, mut requests, _cred) = auth_covering_other(); - let session = ScriptedSession::per_stream_eof(vec![subscribe_update_with_token(VERSION, true).await]); - let h = serve_on(VERSION, auth, session); + let (auth, requests, _cred) = auth_covering_other(); + let session = ScriptedSession::new(subscribe_update_with_token(VERSION, true).await); + let h = serve_on(VERSION, auth, session.clone()); + let stream = Stream::open(&mut crate::driver::Transport::new(h.session.clone()), VERSION) + .await + .unwrap(); + let cancel = || session.close(crate::lite::test_transport::Close::Fin); + ends_while_a_renewal_is_pending(&h, requests, stream, cancel, "draft-18").await; + } + + /// Serve a token-authorized SUBSCRIBE, and `cancel` it once the acceptor holds a renewal. Its + /// demand ends at once; the request ends only once the renewal is dropped. + async fn ends_while_a_renewal_is_pending( + h: &Serve, + mut requests: crate::auth::Requests, + stream: Stream, + cancel: impl FnOnce(), + label: &str, + ) { let mut group = h.track.create_group(group::Info { sequence: 0 }).unwrap(); group.write_frame(timestamp(), b"frame".as_slice()).unwrap(); group.finish().unwrap(); settle().await; - let stream = Stream::open(&mut crate::driver::Transport::new(h.session.clone()), VERSION) - .await - .unwrap(); - let popped = std::sync::Arc::new(AtomicU64::new(0)); + let renewal = std::sync::Arc::new(std::sync::Mutex::new(None)); let acceptor = { - let popped = popped.clone(); + let renewal = renewal.clone(); async move { let first = requests.next().await.expect("a request"); let _issued = first.accept(crate::auth::Grant::all()); - popped.fetch_add(1, Ordering::Relaxed); - let _never_answered = requests.next().await.expect("a renewal"); - popped.fetch_add(1, Ordering::Relaxed); + *renewal.lock().unwrap() = Some(requests.next().await.expect("a renewal")); std::future::pending::<()>().await } }; let mut acceptor = std::pin::pin!(acceptor); let mut serving = std::pin::pin!(h.publisher.clone().run_subscribe_stream(stream, token_subscribe())); - let mut ended = false; for _ in 0..500 { let _ = futures::poll!(acceptor.as_mut()); - if futures::poll!(serving.as_mut()).is_ready() { - ended = true; + assert!( + futures::poll!(serving.as_mut()).is_pending(), + "{label}: ended before the cancel" + ); + if renewal.lock().unwrap().is_some() { break; } settle().await; } assert!( - popped.load(Ordering::Relaxed) >= 1, - "the subscription was token-authorized" + renewal.lock().unwrap().is_some(), + "{label}: the acceptor never saw the renewal" + ); + assert!( + h.track.subscription().is_some(), + "{label}: the subscription is not serving" ); + + cancel(); + for _ in 0..10 { + assert!( + futures::poll!(serving.as_mut()).is_pending(), + "{label}: the request let go of its stream while the acceptor held the renewal" + ); + settle().await; + } assert!( - ended, - "closing the stream ends the subscription despite the pending renewal" + h.track.subscription().is_none(), + "{label}: the cancel did not end the subscription's demand" ); + + drop(renewal.lock().unwrap().take()); + let mut ended = false; + for _ in 0..10 { + if futures::poll!(serving.as_mut()).is_ready() { + ended = true; + break; + } + settle().await; + } + assert!(ended, "{label}: dropping the renewal ends the request"); } /// One UNSUBSCRIBE keyed to the subscription, the draft-14/15/16 cancellation message. @@ -13123,49 +13139,22 @@ mod serve_tests { } /// Before draft-17 a cancellation is an UNSUBSCRIBE message, not a FIN. It must end the - /// request even while a renewal verdict is pending: with a non-expiring grant and an - /// acceptor that never answers the renewal, the UNSUBSCRIBE is the only thing that can. + /// subscription even while a renewal verdict is pending: with a non-expiring grant and an + /// acceptor sitting on the renewal, the UNSUBSCRIBE is the only thing that can. #[moq_clock::test] async fn a_pending_renewal_ends_on_an_unsubscribe_before_draft_17() { for version in [Version::Draft14, Version::Draft15, Version::Draft16] { - let (auth, mut requests, _cred) = auth_covering_other(); - // The stream carries the renewal then the UNSUBSCRIBE and never FINs, so only the + let (auth, requests, _cred) = auth_covering_other(); + // The stream carries the renewal, then the UNSUBSCRIBE, and never FINs, so only the // message can end the request. - let script = [ - subscribe_update_with_token(version, true).await, - unsubscribe_bytes(version).await, - ] - .concat(); - let h = serve_with_auth(version, auth, script); - let mut group = h.track.create_group(group::Info { sequence: 0 }).unwrap(); - group.write_frame(timestamp(), b"frame".as_slice()).unwrap(); - group.finish().unwrap(); - settle().await; - + let session = ScriptedSession::new(subscribe_update_with_token(version, true).await); + let h = serve_on(version, auth, session.clone()); let stream = Stream::open(&mut crate::driver::Transport::new(h.session.clone()), version) .await .unwrap(); - let acceptor = async move { - let first = requests.next().await.expect("a request"); - let _issued = first.accept(crate::auth::Grant::all()); - let _never_answered = requests.next().await.expect("a renewal"); - std::future::pending::<()>().await - }; - let mut acceptor = std::pin::pin!(acceptor); - let mut serving = std::pin::pin!(h.publisher.clone().run_subscribe_stream(stream, token_subscribe())); - let mut ended = false; - for _ in 0..500 { - let _ = futures::poll!(acceptor.as_mut()); - if futures::poll!(serving.as_mut()).is_ready() { - ended = true; - break; - } - settle().await; - } - assert!( - ended, - "{version:?}: an UNSUBSCRIBE ends the subscription despite the pending renewal" - ); + let unsubscribe = unsubscribe_bytes(version).await; + let cancel = || session.push(&unsubscribe); + ends_while_a_renewal_is_pending(&h, requests, stream, cancel, &format!("{version:?}")).await; } } @@ -13249,7 +13238,8 @@ mod serve_tests { } /// A slow acceptor answering a renewal must not stall serving nor let the request outlive - /// its grant: the renewal verify is raced against the old deadline, which still fires. + /// its grant: the renewal verify is raced against the old deadline, which still fires and + /// sends PUBLISH_DONE. The stream keeps its credit until the acceptor lets go of the renewal. #[moq_clock::test] async fn a_slow_renewal_does_not_stall_serving() { const VERSION: Version = Version::Draft18; @@ -13281,7 +13271,7 @@ mod serve_tests { std::future::pending::<()>().await } }; - let mut acceptor = std::pin::pin!(acceptor); + let mut acceptor = Box::pin(acceptor); let mut serving = std::pin::pin!(h.publisher.clone().run_subscribe_stream(stream, token_subscribe())); // Let the loop read the REQUEST_UPDATE and the acceptor pop both requests. @@ -13301,16 +13291,46 @@ mod serve_tests { // The acceptor is stuck. Past the old 60s expiry the deadline must still fire and end // the request EXPIRED, rather than the pending renewal stalling serving. moq_clock::sim::advance(Duration::from_secs(120)).await; - let mut ended = None; + let done = { + let log = Log::default(); + let mut writer = crate::coding::Writer::new( + crate::transport::boxed::SendStream::new(crate::lite::test_transport::SinkSend::new(log.clone())), + VERSION, + ); + writer.varint(ietf::PublishDone::ID).await.unwrap(); + log.writes.lock().unwrap().clone() + }; + let request = |sent: &crate::lite::test_transport::Sent| h.log.trail().contains(&(0, sent.clone())); for _ in 0..50 { let _ = futures::poll!(acceptor.as_mut()); + assert!( + futures::poll!(serving.as_mut()).is_pending(), + "the request let go of its stream while the acceptor held the renewal" + ); + if request(&crate::lite::test_transport::Sent::Write(done.clone())) { + break; + } + settle().await; + } + assert!( + request(&crate::lite::test_transport::Sent::Write(done.clone())), + "serving must end at the old deadline, not stall on the slow renewal" + ); + assert!( + !request(&crate::lite::test_transport::Sent::Finish), + "the stream closed while the acceptor held the renewal" + ); + + drop(acceptor); + let mut ended = None; + for _ in 0..10 { if let Poll::Ready(res) = futures::poll!(serving.as_mut()) { ended = Some(res); break; } settle().await; } - let res = ended.expect("serving must end at the old deadline, not stall on the slow renewal"); + let res = ended.expect("dropping the renewal ends the request"); assert!(matches!(res, Err(Error::Expired)), "{res:?}"); } @@ -13715,6 +13735,53 @@ mod serve_tests { ); } + /// A peer that cancels a SUBSCRIBE whose token the application took keeps the request's + /// stream, and so its credit, until the application answers: cancelling and resubscribing + /// cannot leave more verifications in flight than the peer's credit admits. + #[moq_clock::test] + async fn a_cancelled_subscribe_keeps_its_stream_until_the_application_answers() { + const VERSION: Version = Version::Draft18; + let auth = crate::auth::Handle::new(false); + let mut requests = auth.requests().unwrap(); + let h = serve_with_auth(VERSION, auth, Vec::new()); + let stream = Stream::open(&mut crate::driver::Transport::new(h.session.clone()), VERSION) + .await + .unwrap(); + let mut serving = std::pin::pin!(h.publisher.clone().run_subscribe_stream(stream, token_subscribe())); + let mut taken = None; + for _ in 0..10 { + assert!(futures::poll!(serving.as_mut()).is_pending(), "verification is pending"); + if taken.is_none() + && let Poll::Ready(Some(request)) = requests.poll_next(&kio::Waiter::noop()) + { + taken = Some(request); + } + settle().await; + } + let taken = taken.expect("the application took the token"); + + h.session.close(crate::lite::test_transport::Close::Reset); + for _ in 0..10 { + assert!( + futures::poll!(serving.as_mut()).is_pending(), + "the cancelled request let go of its stream before the application answered" + ); + settle().await; + } + let ended = taken.closed().await; + assert!( + matches!(ended, Error::Cancel), + "the application sees the cancel: {ended:?}" + ); + + drop(taken.accept(crate::auth::Grant::all())); + let res = futures::poll!(serving.as_mut()); + assert!( + matches!(res, Poll::Ready(Ok(()))), + "answered, the request ends: {res:?}" + ); + } + /// What the peer granted us bounds what we send, so a request token never admits a /// SUBSCRIBE outside it, and the application is not even asked. #[moq_clock::test] diff --git a/rs/moq-net/src/ietf/publisher/tracks.rs b/rs/moq-net/src/ietf/publisher/tracks.rs index b95f79869a2..155ed3f5d7e 100644 --- a/rs/moq-net/src/ietf/publisher/tracks.rs +++ b/rs/moq-net/src/ietf/publisher/tracks.rs @@ -671,8 +671,9 @@ impl Publisher { let Ok(track) = broadcast.track(&name) else { continue; }; - // Each paused PUBLISH holds a subscription slot; past the cap the peer is - // told the track exists rather than left without it. + // Each paused PUBLISH holds a subscription slot. Nothing else bounds how many + // a peer's listings hold, so past `Limits::requests` the peer is told the + // track exists rather than left without it. let Ok(slot) = self.subscriptions.acquire() else { skip(name); continue; @@ -872,7 +873,7 @@ impl Publisher { if let Some(done) = refused { drop(join); - return self.write_publish_done(stream, request_id, done, 0).await; + return self.write_publish_done(stream, request_id, done, 0, None).await; } // Group streams opened over every time the subscription forwarded, which @@ -1008,7 +1009,7 @@ impl Publisher { }; drop(join); - self.write_publish_done(stream, request_id, done, opened).await + self.write_publish_done(stream, request_id, done, opened, None).await } /// Mark a paused subscription for joining FETCHes: draft-18 section 5.1 refuses one @@ -1698,10 +1699,10 @@ mod tests { } } - /// Each paused PUBLISH holds a subscription slot; past the cap the track is skipped - /// (PUBLISH_BLOCKED, the same message, on draft-18) rather than held. + /// Each paused PUBLISH holds a subscription slot; past `Limits::requests` the track is + /// skipped (PUBLISH_BLOCKED, the same message, on draft-18) rather than held. #[moq_clock::test] - async fn past_the_subscription_cap_a_track_is_skipped() { + async fn past_the_request_limit_a_track_is_skipped() { for version in DRAFTS { let mut h = harness(version); h.publisher.subscriptions = crate::session::Slots::new(1); diff --git a/rs/moq-net/src/ietf/session.rs b/rs/moq-net/src/ietf/session.rs index 76c8aad76a1..b0c58245fba 100644 --- a/rs/moq-net/src/ietf/session.rs +++ b/rs/moq-net/src/ietf/session.rs @@ -215,8 +215,8 @@ pub fn start(config: Config) -> Result<(Driver, crate::goaway::Handle), Error> { .with_stats(stats.clone()) }); let subscribe = subscribe.unwrap_or_else(|| origin::Producer::empty(Hop::random()).with_stats(stats.clone())); - let subscriptions = crate::session::Slots::new(limits.subscriptions) - .with_stats(publish.stats(), crate::stats::Cap::Subscriptions); + let subscriptions = + crate::session::Slots::new(limits.requests).with_stats(publish.stats(), crate::stats::Cap::Subscriptions); let announces = crate::session::Slots::new(limits.announces).with_stats(subscribe.stats(), crate::stats::Cap::Announces); @@ -230,7 +230,7 @@ pub fn start(config: Config) -> Result<(Driver, crate::goaway::Handle), Error> { ); return Err(err); }; - let control = Control::new(request_id_max, client).with_window(limits.requests(), client, version); + let control = Control::new(request_id_max, client).with_window(limits.window(), client, version); let adapter = ControlStreamAdapter::new(session.clone(), control.clone(), version).with_stats(&stats); // Boxed like a draft-17+ transport, so the publisher and subscriber below // are the same instantiation as theirs. @@ -251,7 +251,6 @@ pub fn start(config: Config) -> Result<(Driver, crate::goaway::Handle), Error> { publisher.withdrawal = withdrawing.clone(); publisher.owed = serving.clone(); publisher.subscriptions = subscriptions; - publisher.fetches = crate::session::Slots::new(limits.fetches); let mut subscriber = Subscriber::new( runtime.clone(), @@ -411,7 +410,7 @@ pub fn start(config: Config) -> Result<(Driver, crate::goaway::Handle), Error> { res } _ => { - let control = Control::new(None, client).with_history(limits.requests()); + let control = Control::new(None, client).with_history(limits.window()); // Send SETUP and retain its writer for the session's lifetime. Only a failure // ends the session; the other branches report how it closed. let setup = err_only(run_setup( @@ -444,7 +443,6 @@ pub fn start(config: Config) -> Result<(Driver, crate::goaway::Handle), Error> { publisher.withdrawal = withdrawing.clone(); publisher.owed = serving.clone(); publisher.subscriptions = subscriptions; - publisher.fetches = crate::session::Slots::new(limits.fetches); // Only the dialing side fails loud on a publication outside its grant: a // server's publish origin is everything the peer may read, not what it diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index c8d1a12909c..f060824c944 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -52,9 +52,8 @@ pub(super) struct PublisherConfig { pub estimate: kio::ProducerWeak, /// Whether we dialed: only then does a publication outside our grant abort. pub client: bool, - /// Subscriptions the peer may hold at once (`session::Limits::subscriptions`). + /// Counts the subscriptions the peer holds, for the session's subscriptions peak. pub subscriptions: crate::session::Slots, - pub fetches: crate::session::Slots, } /// Context shared by every control-stream child. @@ -83,10 +82,10 @@ struct Shared { peer_grant: crate::auth::Grant, // Control streams still serving the peer data, which a draining close waits for. owed: AtomicUsize, - interests: Interests, + // The subscriptions the peer holds, counted for the stats peak. + subscriptions: crate::session::Slots, /// Holds this session's listings: one per broadcast, the newest replacing the rest. lister: crate::broadcast::Owner, - fetches: crate::session::Slots, // The send time an untimed track's frames carry on Lite05/06, which can't mark them // untimed (see `wire_timestamp`). runtime: crate::time::Deadlines, @@ -215,9 +214,8 @@ impl Publisher { auth: config.auth, peer_grant: config.peer_grant, owed: AtomicUsize::new(0), - interests: Interests::new(config.subscriptions), + subscriptions: config.subscriptions, lister: crate::broadcast::Owner::new(), - fetches: config.fetches, runtime: config.runtime.clone(), estimate: config.estimate, }), @@ -1497,10 +1495,9 @@ trait Request: Sized { /// Whether we answer the requester's FIN with our own. Otherwise we reset: the reply /// would end short, and a FIN there would read as a whole one. const GRACEFUL: bool; - /// What the request counts as against the session's subscription cap while it is open. - const CHARGE: Option; - /// Whether the incoming request holds an independent FETCH slot. - const FETCH: bool = false; + /// Whether the request counts toward the session's subscriptions peak while it is open. + /// Its stream's credit, not a count, bounds how many the peer holds. + const SUBSCRIPTION: bool = false; /// Whether the request stays open past its reply, keeping what serving it took, until /// the requester closes its side. const HOLDS: bool; @@ -1555,9 +1552,8 @@ struct RequestServe { state: RequestState, // Counted in `Shared::owed` until the reply is delivered, so a draining close waits for it. owing: bool, - // The request's place under the session's subscription cap. - _charged: Option, - _fetch: Option, + // A subscription's place in the session's subscriptions peak. + _subscription: Option, // The latest update to arrive before the reply started. Each one replaces the last. update: Option, /// Ends the request, even mid-reply, once the session stops allowing its broadcast. @@ -1601,8 +1597,7 @@ impl RequestServe { stream: Some(stream), state: RequestState::Decode, owing: true, - _charged: None, - _fetch: None, + _subscription: None, update: None, gate: None, absolute: Default::default(), @@ -1671,33 +1666,11 @@ impl RequestServe { match &mut self.state { RequestState::Decode => { let msg = ready!(stream.reader.poll_decode::(&mut cx))?; - if R::FETCH { - self._fetch = match self.shared.fetches.acquire() { - Ok(slot) => Some(slot), - Err(err) => { - self.shared.session.clone().close( - crate::lite::error::to_session_code(&crate::SessionError::from(&err)), - "too many fetches", - ); - return Poll::Ready(Err(err)); - } - }; - } let (broadcast, track) = R::target(&msg); self.absolute = self.shared.origin.absolute(broadcast).to_owned(); self.track = track.to_string(); - if let Some(charge) = R::CHARGE { - match self.shared.interests.charge(broadcast, track, charge) { - Ok(charged) => self._charged = Some(charged), - // A peer past its limits loses the session, not just this request. - Err(err) => { - self.shared.session.clone().close( - crate::lite::error::to_session_code(&crate::SessionError::from(&err)), - "too many subscriptions", - ); - return Poll::Ready(Err(err)); - } - } + if R::SUBSCRIPTION { + self._subscription = Some(self.shared.subscriptions.hold()); } tracing::info!(broadcast = %self.absolute, track = %self.track, request = ?msg, "{} started", R::KIND); // Checked before anything is resolved, so a broadcast the session does not @@ -1827,109 +1800,6 @@ impl Drop for RequestServe { } } -/// What a request counts as against the session's subscription cap. -#[derive(Clone, Copy)] -enum Charge { - /// A TRACK stream, held open as interest in the track. - Track, - /// A subscription. - Subscribe, - /// A TRACKS stream listing the broadcast, charged under the empty track name on top - /// of any interest in a track of that name. Each listing is charged until it is gone, - /// replaced or not: which listing a newer one replaces is known only once both - /// resolve, so like a repeated SUBSCRIBE, a replacement must fit under the cap. - Tracks, -} - -/// A session's subscription cap, charged per track. -/// -/// A TRACK stream held open and the SUBSCRIBE that follows it are one interest in the -/// track, so a track costs the larger of its two counts: a peer at the cap can still -/// subscribe to the tracks it holds. -struct Interests { - slots: crate::session::Slots, - tracks: kio::Lock>, -} - -/// The requests open on one track, and the slots they take. -#[derive(Default)] -struct Interest { - tracks: usize, - subscribes: usize, - listings: usize, - slots: Vec, -} - -impl Interest { - fn count(&mut self, charge: Charge) -> &mut usize { - match charge { - Charge::Track => &mut self.tracks, - Charge::Subscribe => &mut self.subscribes, - Charge::Tracks => &mut self.listings, - } - } - - fn cost(&self) -> usize { - self.tracks.max(self.subscribes) + self.listings - } -} - -impl Interests { - fn new(slots: crate::session::Slots) -> Self { - Self { - slots, - tracks: kio::Lock::new(HashMap::new()), - } - } - - /// Charge a request for `broadcast`'s `track` until the returned guard drops, or - /// [`Error::TooManyRequests`] past the cap. - fn charge(&self, broadcast: &crate::Path, track: &str, charge: Charge) -> Result { - let key = (broadcast.to_owned(), track.to_string()); - let mut tracks = self.tracks.lock(); - let interest = tracks.entry(key.clone()).or_default(); - *interest.count(charge) += 1; - if interest.cost() > interest.slots.len() { - match self.slots.acquire() { - Ok(slot) => interest.slots.push(slot), - Err(err) => { - *interest.count(charge) -= 1; - if interest.cost() == 0 { - tracks.remove(&key); - } - return Err(err); - } - } - } - Ok(Charged { - tracks: self.tracks.clone(), - key, - charge, - }) - } -} - -/// One request's charge on its track, released on drop. -struct Charged { - tracks: kio::Lock>, - key: (crate::PathOwned, String), - charge: Charge, -} - -impl Drop for Charged { - fn drop(&mut self) { - let mut tracks = self.tracks.lock(); - let Some(interest) = tracks.get_mut(&self.key) else { - return; - }; - *interest.count(self.charge) -= 1; - interest.slots.truncate(interest.cost()); - if interest.cost() == 0 { - tracks.remove(&self.key); - } - } -} - /// Answers a TRACK stream with the track's TRACK_INFO. /// /// The open stream is interest in the track: the query that answered it stays until the @@ -1941,7 +1811,6 @@ struct TrackInfoServe { impl Request for TrackInfoServe { const KIND: &'static str = "track info"; const GRACEFUL: bool = false; - const CHARGE: Option = Some(Charge::Track); const HOLDS: bool = true; type Message = lite::Track<'static>; type Update = NoUpdate; @@ -1996,7 +1865,6 @@ struct TracksServe { impl Request for TracksServe { const KIND: &'static str = "tracks"; const GRACEFUL: bool = false; - const CHARGE: Option = Some(Charge::Tracks); const HOLDS: bool = false; type Message = lite::Tracks<'static>; type Update = NoUpdate; @@ -2078,7 +1946,7 @@ impl Request for SubscribeServe { const KIND: &'static str = "subscribed"; // Ending a subscription early is still a valid end. const GRACEFUL: bool = true; - const CHARGE: Option = Some(Charge::Subscribe); + const SUBSCRIPTION: bool = true; const HOLDS: bool = false; type Message = lite::Subscribe<'static>; type Update = lite::SubscribeUpdate; @@ -2266,10 +2134,8 @@ type Objects = arrayvec::ArrayVec; impl Request for FetchServe { const KIND: &'static str = "fetch"; - const FETCH: bool = true; // The response carries no header, so a run cut short would read as whole. const GRACEFUL: bool = false; - const CHARGE: Option = None; const HOLDS: bool = false; type Message = lite::Fetch<'static>; type Update = NoUpdate; @@ -7041,7 +6907,6 @@ mod tests { peer_grant: Default::default(), client: false, subscriptions: Default::default(), - fetches: Default::default(), estimate: kio::Producer::default().weak(), }); @@ -7218,7 +7083,6 @@ mod tests { peer_grant: Default::default(), client: false, subscriptions: Default::default(), - fetches: Default::default(), estimate: estimate.weak(), }); ProbeServe::new(publisher.shared.clone(), publisher.runtime.clone(), stream) @@ -7519,7 +7383,6 @@ mod tests { peer_grant: Default::default(), client: false, subscriptions: Default::default(), - fetches: Default::default(), estimate: kio::Producer::default().weak(), }); @@ -7649,7 +7512,6 @@ mod tests { goaway, peer_hop: None, subscriptions: Default::default(), - fetches: Default::default(), auth: crate::auth::Handle::new(false), peer_grant: Default::default(), client: false, @@ -7747,7 +7609,6 @@ mod tests { peer_grant: Default::default(), client: false, subscriptions: Default::default(), - fetches: Default::default(), estimate: kio::Producer::default().weak(), }); @@ -7863,7 +7724,6 @@ mod tests { goaway, peer_hop: None, subscriptions: Default::default(), - fetches: Default::default(), auth: crate::auth::Handle::new(false), peer_grant: Default::default(), client: false, @@ -7966,81 +7826,6 @@ mod tests { ); } - /// A SUBSCRIBE or a TRACK past the session's cap closes the session with - /// TOO_MANY_REQUESTS. - #[moq_clock::test] - async fn requests_past_the_cap_close_the_session() { - use crate::coding::Encode as _; - - const VERSION: Version = Version::Lite06; - let encode = |kind: lite::ControlType, msg: &dyn Fn(&mut Vec)| { - let mut script = Vec::new(); - kind.encode(&mut crate::coding::Encoder::new(&mut script, VERSION.into()), VERSION) - .unwrap(); - msg(&mut script); - script - }; - let subscribe = encode(lite::ControlType::Subscribe, &|script| { - lite::Subscribe { - order: crate::track::Order::Descending, - epoch: None, - id: 0, - broadcast: crate::Path::new("room"), - track: "video".into(), - priority: 0, - max_delay: Duration::ZERO, - start_group: None, - end_group: None, - start_frame: 0, - end_frame: None, - } - .encode(&mut crate::coding::Encoder::new(script, VERSION.into()), VERSION) - .unwrap() - }); - let track = encode(lite::ControlType::Track, &|script| { - lite::Track { - epoch: None, - broadcast: crate::Path::new("room"), - track: "video".into(), - } - .encode(&mut crate::coding::Encoder::new(script, VERSION.into()), VERSION) - .unwrap() - }); - - for script in [subscribe, track] { - let session = - crate::lite::test_transport::ScriptedSession::new(Vec::new()).with_incoming_bidis(vec![script]); - let log = session.log.clone(); - - let origin = Hop::random().produce(); - let (_, goaway) = crate::goaway::Handle::new(true); - let mut publisher = Publisher::new(PublisherConfig { - estimate: kio::Producer::default().weak(), - runtime: crate::time::sim(), - session: crate::driver::Transport::new(session.clone()), - origin: origin.consume(), - version: VERSION, - peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Binding::InBand), - goaway, - peer_hop: None, - subscriptions: crate::session::Slots::new(0), - fetches: Default::default(), - auth: crate::auth::Handle::new(false), - peer_grant: Default::default(), - client: false, - }); - - let _ = publisher.poll(&kio::Waiter::noop()); - assert_eq!( - log.closes(), - vec![( - crate::SessionError::TooManyRequests.to_code(), - "too many subscriptions".to_string() - )] - ); - } - } - /// A FETCH whose own budget gives up on its group partway resets as too old: a FIN /// would tell the requester the prefix it got is the whole group. #[moq_clock::test] @@ -8068,7 +7853,6 @@ mod tests { peer_grant: Default::default(), client: false, subscriptions: Default::default(), - fetches: Default::default(), estimate: kio::Producer::default().weak(), }); let mut script = Vec::new(); @@ -8109,138 +7893,6 @@ mod tests { assert_eq!(session.log.resets(), vec![crate::StreamError::Old.to_code()]); } - /// Shared model demand never shares admission slots between wire FETCH streams. - #[moq_clock::test] - async fn coalesced_fetches_each_hold_their_own_slot() { - const VERSION: Version = Version::Lite06; - let origin = crate::origin::Config::new(Hop::new(1).unwrap()).produce(); - let broadcast = origin.create_broadcast("room").unwrap(); - let track = broadcast - .create_track("video", track::Info::default().with_timescale(None)) - .unwrap(); - let groups = track.dynamic(); - broadcast.announce(Default::default()).unwrap(); - let peer_setup = crate::lite::PeerSetup::new(false, crate::transport::Binding::InBand); - peer_setup.set(crate::lite::Setup::default()); - let (_, goaway) = crate::goaway::Handle::new(true); - let session = ScriptedSession::new(Vec::new()); - let log = session.log.clone(); - let publisher = Publisher::new(PublisherConfig { - runtime: crate::time::sim(), - session: crate::driver::Transport::new(session), - origin: origin.consume(), - version: VERSION, - peer_setup, - goaway, - peer_hop: None, - auth: crate::auth::Handle::new(false), - peer_grant: Default::default(), - client: false, - subscriptions: crate::session::Slots::new(0), - fetches: crate::session::Slots::new(2), - estimate: kio::Producer::default().weak(), - }); - let mut script = Vec::new(); - lite::Fetch { - epoch: None, - broadcast: crate::Path::new("room"), - track: "video".into(), - priority: 0, - max_delay: None, - group: 7, - start_frame: 0, - end_frame: None, - } - .encode(&mut crate::coding::Encoder::new(&mut script, VERSION.into()), VERSION) - .unwrap(); - let waiter = kio::Waiter::noop(); - let mut held = Vec::new(); - for count in 0..3 { - let mut session = ScriptedSession::new(script.clone()); - let (send, recv) = futures::future::poll_fn(|cx| { - ::poll_open_bi(&mut session, cx, Default::default()) - }) - .await - .unwrap(); - let stream = Stream:: { - writer: Writer::new(crate::transport::boxed::SendStream::new(send), VERSION), - reader: crate::coding::Reader::new(crate::transport::boxed::RecvStream::new(recv), VERSION), - }; - let mut request = RequestServe::::new(publisher.shared.clone(), stream); - if count < 2 { - assert!(!drive(&mut request).await); - held.push(request); - } else { - assert!(matches!( - request.poll(&waiter), - Poll::Ready(Err(Error::TooManyRequests)) - )); - } - } - let _request = groups - .requested_group() - .now_or_never() - .expect("one shared fetch") - .unwrap(); - assert!( - groups.requested_group().now_or_never().is_none(), - "same group coalesces in the model" - ); - assert_eq!( - log.closes(), - vec![( - crate::SessionError::TooManyRequests.to_code(), - "too many fetches".to_owned() - )] - ); - assert!(publisher.shared.fetches.acquire().is_err()); - drop(held.pop()); - assert!( - publisher.shared.fetches.acquire().is_ok(), - "drop returns exactly one incoming slot" - ); - } - - /// A TRACK held open and the SUBSCRIBE for the same track are one interest, whichever - /// arrives first, while another track costs a slot of its own. - #[test] - fn a_track_and_its_subscription_share_a_slot() { - let slots = crate::session::Slots::new(1); - let interests = Interests::new(slots.clone()); - let room = crate::Path::new("room"); - - for (first, second) in [(Charge::Track, Charge::Subscribe), (Charge::Subscribe, Charge::Track)] { - let a = interests.charge(&room, "video", first).expect("the first fits"); - let b = interests - .charge(&room, "video", second) - .expect("shares the first's slot"); - assert!(matches!( - interests.charge(&room, "audio", Charge::Track), - Err(Error::TooManyRequests) - )); - // Either leaving keeps the slot for the other. - drop(a); - assert!(slots.acquire().is_err(), "the remaining request lost its slot"); - drop(b); - drop(slots.acquire().expect("the slot was not returned")); - } - - // Each listing is its own interest, even one that will replace another. - let listing = interests.charge(&room, "", Charge::Tracks).expect("the listing fits"); - assert!(matches!( - interests.charge(&room, "", Charge::Tracks), - Err(Error::TooManyRequests) - )); - drop(listing); - - // Two of a kind are two interests. - let _a = interests.charge(&room, "video", Charge::Subscribe).unwrap(); - assert!(matches!( - interests.charge(&room, "video", Charge::Subscribe), - Err(Error::TooManyRequests) - )); - } - #[moq_clock::test] async fn report_consumes_probe_targets_until_fin() { for version in [ @@ -8564,7 +8216,6 @@ mod tests { peer_grant: Default::default(), client: false, subscriptions: Default::default(), - fetches: Default::default(), estimate: kio::Producer::default().weak(), }); (publisher, log) diff --git a/rs/moq-net/src/lite/session.rs b/rs/moq-net/src/lite/session.rs index d6bd8b3f932..d2ed36546c5 100644 --- a/rs/moq-net/src/lite/session.rs +++ b/rs/moq-net/src/lite/session.rs @@ -262,8 +262,7 @@ pub fn start(config: Config) -> Result { .with_stats(stats.clone()) }); let subscribe = subscribe.unwrap_or_else(|| origin::Producer::empty(Hop::random()).with_stats(stats.clone())); - let subscriptions = - crate::session::Slots::new(limits.subscriptions).with_stats(publish.stats(), crate::stats::Cap::Subscriptions); + let subscriptions = crate::session::Slots::default().with_stats(publish.stats(), crate::stats::Cap::Subscriptions); let announces = crate::session::Slots::new(limits.announces).with_stats(subscribe.stats(), crate::stats::Cap::Announces); @@ -314,7 +313,6 @@ pub fn start(config: Config) -> Result { peer_grant, client, subscriptions, - fetches: crate::session::Slots::new(limits.fetches), }); let mut subscriber = Subscriber::new(SubscriberConfig { runtime: runtime.clone(), diff --git a/rs/moq-net/src/server.rs b/rs/moq-net/src/server.rs index fd1103dac9b..adfd46f63ea 100644 --- a/rs/moq-net/src/server.rs +++ b/rs/moq-net/src/server.rs @@ -635,7 +635,7 @@ impl PausedLegacy { // The client's requests, admitted up to our limits and granted back as they close. parameters.set_varint( ietf::ParameterVarInt::MaxRequestId, - ietf::initial_max_request_id(server.limits.requests(), true), + ietf::initial_max_request_id(server.limits.window(), true), ); parameters.set_bytes(ietf::ParameterBytes::Implementation, b"moq-lite-rs".to_vec()); if server.extensions.solicit { @@ -816,7 +816,7 @@ impl Handshake { self } - /// Set request caps after authorizing the peer and before answering SETUP. + /// Set the session's limits after authorizing the peer and before answering SETUP. pub fn with_limits(mut self, limits: crate::session::Limits) -> Self { self.inner_mut().server.limits = limits; self diff --git a/rs/moq-net/src/session.rs b/rs/moq-net/src/session.rs index 25334f34845..f38f3894def 100644 --- a/rs/moq-net/src/session.rs +++ b/rs/moq-net/src/session.rs @@ -756,26 +756,31 @@ impl Drop for Withdrawing { } } -/// Caps on what one peer can make a session hold at once. +/// Bounds on what one peer can make a session hold, where its transport does not already. /// -/// A peer that goes past a cap loses the session, closed with `TOO_MANY_REQUESTS`. The -/// stats sessions rows report announcement and subscription peaks. +/// Each moq-lite request, and each moq-transport request from draft 17 on, holds a stream +/// of its own, so the transport's stream credit bounds those. A peer that announces past +/// `announces`, or overruns the drafts 14 to 16 request window, loses the session, closed with +/// `TOO_MANY_REQUESTS`. The stats sessions rows report announcement and subscription peaks. /// -/// On moq-transport drafts 14 to 16 the caps also size the request window, which counts -/// every request (FETCH, TRACK_STATUS and SUBSCRIBE_UPDATE included), so very low caps -/// can starve it. Later drafts have no window but still refuse a reused request ID, so a -/// peer may leave at most twice the sum of these caps runs of skipped IDs; one more closes -/// the session with `INTERNAL_ERROR` rather than forgetting any. +/// ``` +/// let mut limits = moq_net::session::Limits::default(); +/// limits.announces = 1_000; +/// let client = moq_net::Client::new().with_limits(limits); +/// ``` #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[non_exhaustive] pub struct Limits { /// Broadcasts (moq-lite) or namespaces (moq-transport) the peer may have announced to us. pub announces: usize, - /// Subscriptions the peer may hold on our broadcasts. On moq-lite 05 and later an open - /// TRACK stream holds one too, sharing it with a SUBSCRIBE for the same track. - pub subscriptions: usize, - /// FETCH requests the peer may hold before group coalescing, defaulting to 10,000. - pub fetches: usize, + /// Other moq-transport requests the peer may hold at once, such as SUBSCRIBE and FETCH. + /// + /// On drafts 14 to 16 this and `announces` size the request window, which every request + /// counts against. Later drafts bound the PUBLISHes a peer's track listings hold with it, + /// skipping the rest, and still refuse a reused request ID, so a peer may leave at most + /// twice the sum of both runs of skipped IDs; one more closes the session with + /// `INTERNAL_ERROR` rather than forgetting any. moq-lite ignores it. + pub requests: usize, } impl Default for Limits { @@ -783,8 +788,7 @@ impl Default for Limits { fn default() -> Self { Self { announces: 100_000, - subscriptions: 10_000, - fetches: 10_000, + requests: 20_000, } } } @@ -792,14 +796,10 @@ impl Default for Limits { impl Limits { /// How many requests a moq-transport peer may hold open at once (drafts 14 to 16). /// - /// Twice what the caps admit, so a peer within them is never blocked by request IDs + /// Twice what the limits admit, so a peer within them is never blocked by request IDs /// still waiting to be granted back. - pub(crate) fn requests(&self) -> u64 { - let caps = self - .announces - .saturating_add(self.subscriptions) - .saturating_add(self.fetches) as u64; - caps.saturating_mul(2) + pub(crate) fn window(&self) -> u64 { + (self.announces.saturating_add(self.requests) as u64).saturating_mul(2) } } @@ -847,10 +847,21 @@ impl Slots { }) .map_err(|_| Error::TooManyRequests)? + 1; + Ok(self.held(held)) + } + + /// Count one entry the transport already bounds until the returned guard drops, past the + /// cap too, so entries taken with [`Self::acquire`] see it. + pub(crate) fn hold(&self) -> Slot { + let held = self.live.fetch_add(1, std::sync::atomic::Ordering::AcqRel) + 1; + self.held(held) + } + + fn held(&self, held: usize) -> Slot { if let Some((stats, cap)) = &self.stats { stats.hold(*cap, held as u64); } - Ok(Slot(self.live.clone())) + Slot(self.live.clone()) } } diff --git a/rs/moq-net/src/stats.rs b/rs/moq-net/src/stats.rs index 09ab8df7f93..3d6113026ff 100644 --- a/rs/moq-net/src/stats.rs +++ b/rs/moq-net/src/stats.rs @@ -82,7 +82,7 @@ //! its final nonnegative delta. Unsupported transports contribute zero. //! * `announces_peak` / `subscriptions_peak` ([`Presence`]): the most //! announcements, or subscriptions, any one session under the label held -//! at once, to compare against its `crate::session::Limits`. A peak never +//! at once, to compare against what bounds them. A peak never //! goes down; a rollup takes the largest rather than the sum. //! //! Counters are strictly monotonic (only `fetch_add`); a counter going @@ -673,9 +673,9 @@ impl Traffic { } /// Request admissions and connected-session presence for a label on a tier, or their sum. -/// The session counters are cumulative connects and disconnects. `sessions_started -/// - sessions_ended` is the current live session count. The peaks show how close -/// one session came to its `crate::session::Limits`. +/// The session counters are cumulative connects and disconnects, so +/// `sessions_started - sessions_ended` is the current live session count. The peaks +/// show how close one session came to the bounds on what it holds. /// /// Like [`Traffic`], this is also the wire shape of one entry on a published /// sessions, presence, or totals track. Serialize writes both the canonical names and the legacy @@ -1609,7 +1609,7 @@ pub struct Session { inner: Option>>, } -/// Which of a session's `crate::session::Limits` a [`Session::hold`] counts against. +/// Which peak a [`Session::hold`] raises. #[derive(Clone, Copy, Debug)] pub(crate) enum Cap { #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] diff --git a/rs/moq-net/src/transport/memory.rs b/rs/moq-net/src/transport/memory.rs index 91ec7e502b8..faff2c7e77e 100644 --- a/rs/moq-net/src/transport/memory.rs +++ b/rs/moq-net/src/transport/memory.rs @@ -8,8 +8,9 @@ //! pends while it is full, so a slow reader throttles only its own stream. A write is //! never split: one accepted while the channel has room may overshoot the bound. //! -//! [`Config::max_concurrent_uni_streams`] bounds the uni streams each side has open toward -//! its peer, as QUIC's stream credit does: an open pends until the peer is done with one. +//! [`Config::max_concurrent_uni_streams`] and [`Config::max_concurrent_bi_streams`] bound +//! the streams each side has open toward its peer, as QUIC's stream credit does: an open +//! pends until the peer is done with one. //! //! [`finish`](poll::SendStream::finish) closes the channel cleanly once its messages are //! read. A [`reset`](poll::SendStream::reset) or [`stop`](poll::RecvStream::stop) closes it @@ -52,6 +53,11 @@ pub struct Config { /// A stream is open until its reader reaches the end, stops, or drops it, accepted or /// not. `None` grants credit without limit. pub max_concurrent_uni_streams: Option, + /// Bidi streams one side may have open toward its peer at once, as QUIC's stream credit. + /// A stream is open until the peer is done with both halves: its reader reaches the end, + /// stops, or drops it, and its writer finishes, resets, or drops it. `None` grants credit + /// without limit. + pub max_concurrent_bi_streams: Option, } impl Default for Config { @@ -62,6 +68,7 @@ impl Default for Config { stream_buffer: 1024 * 1024, protocol: None, max_concurrent_uni_streams: None, + max_concurrent_bi_streams: None, } } } @@ -82,6 +89,7 @@ pub fn pair(config: Config) -> (Session, Session) { accept_uni: Default::default(), accept_bi: Default::default(), open_uni: Default::default(), + open_bi: Default::default(), datagram: Default::default(), closed: Default::default(), }; @@ -166,32 +174,71 @@ impl Conn { } } - fn stream(&self, credit: Option>) -> (SendStream, RecvStream) { + /// A one-way stream, whose halves hold `send` and `recv` until each is done. + fn stream(&self, send: Option, recv: Option) -> (SendStream, RecvStream) { let channel = kio::Shared::::default(); - let send = SendStream { + let writer = SendStream { channel: channel.clone(), close: self.close.clone(), buffer: self.config.stream_buffer, done: false, + credit: send, park: Default::default(), }; - let recv = poll::Buffered::new(Chunks { + let reader = poll::Buffered::new(Chunks { channel, close: self.close.clone(), stopped: false, - credit, + credit: recv, park: Default::default(), }); - (send, recv) + (writer, reader) + } +} + +/// One open stream's place in its opener's credit, returned once every half holding it is +/// done. +type Credit = Arc; + +/// Counted in an open-stream total until dropped. +struct Opened(kio::Shared); + +impl Drop for Opened { + fn drop(&mut self) { + *self.0.lock() -= 1; } } +/// Take one stream credit of `max` from `open`, pending until the peer is done with one. +fn poll_credit( + open: &kio::Shared, + max: Option, + close: &Close, + waiter: &kio::Waiter, +) -> Poll, Error>> { + let Some(max) = max else { + return Poll::Ready(Ok(None)); + }; + // Check the close first, so a credit granted before it is still taken below. + let closed = poll_close(close, waiter); + let Poll::Ready(mut count) = open.poll(waiter, |open| match **open < max { + true => Poll::Ready(()), + false => Poll::Pending, + }) else { + return closed.map(Err); + }; + *count += 1; + Poll::Ready(Ok(Some(Arc::new(Opened(open.clone()))))) +} + /// Streams and datagrams one side has yet to accept. struct Incoming { uni: kio::Queue, /// The uni streams toward this side still open, against [`Config::max_concurrent_uni_streams`]. uni_open: kio::Shared, bi: kio::Queue<(SendStream, RecvStream)>, + /// The bidi streams toward this side still open, against [`Config::max_concurrent_bi_streams`]. + bi_open: kio::Shared, datagrams: kio::Queue, } @@ -201,6 +248,7 @@ impl Default for Incoming { uni: kio::Queue::new(), uni_open: Default::default(), bi: kio::Queue::new(), + bi_open: Default::default(), datagrams: kio::Queue::bounded(DATAGRAM_QUEUE), } } @@ -253,6 +301,7 @@ pub struct Session { accept_uni: kio::Park, accept_bi: kio::Park, open_uni: kio::Park, + open_bi: kio::Park, datagram: kio::Park, closed: kio::Park, } @@ -305,34 +354,26 @@ impl poll::Session for Session { _: poll::SendOptions<'_, poll::Ungrouped>, ) -> Poll> { let outgoing = self.side.outgoing(); - let credit = match self.conn().config.max_concurrent_uni_streams { - Some(max) => { - let waiter = self.open_uni.hold(cx); - // Check the close first, so a credit granted before it is still taken below. - let closed = poll_close(&self.side.conn.close, waiter); - let Poll::Ready(mut open) = outgoing.uni_open.poll(waiter, |open| match **open < max { - true => Poll::Ready(()), - false => Poll::Pending, - }) else { - return closed.map(Err); - }; - *open += 1; - Some(outgoing.uni_open.clone()) - } - None => None, - }; - let (send, recv) = self.conn().stream(credit); + let max = self.conn().config.max_concurrent_uni_streams; + let waiter = self.open_uni.hold(cx); + let credit = ready!(poll_credit(&outgoing.uni_open, max, &self.side.conn.close, waiter))?; + let (send, recv) = self.conn().stream(None, credit); Poll::Ready(self.open(&outgoing.uni, recv).map(|()| send)) } fn poll_open_bi( &mut self, - _cx: &mut Context<'_>, + cx: &mut Context<'_>, _: poll::SendOptions<'_, poll::Ungrouped>, ) -> Poll> { - let (send, peer_recv) = self.conn().stream(None); - let (peer_send, recv) = self.conn().stream(None); - let opened = self.open(&self.side.outgoing().bi, (peer_send, peer_recv)); + let outgoing = self.side.outgoing(); + let max = self.conn().config.max_concurrent_bi_streams; + let waiter = self.open_bi.hold(cx); + // The peer's halves both hold the credit, so it returns once the peer is done with both. + let credit = ready!(poll_credit(&outgoing.bi_open, max, &self.side.conn.close, waiter))?; + let (send, peer_recv) = self.conn().stream(None, credit.clone()); + let (peer_send, recv) = self.conn().stream(credit, None); + let opened = self.open(&outgoing.bi, (peer_send, peer_recv)); Poll::Ready(opened.map(|()| (send, recv))) } @@ -431,6 +472,8 @@ pub struct SendStream { buffer: usize, /// This side finished or reset the stream. done: bool, + /// The credit of a bidi stream the peer opened, held until this side is done. + credit: Option, park: kio::Park, } @@ -495,7 +538,9 @@ impl poll::SendStream for SendStream { return Err(Error::Stopped(code)); } channel.end = Some(End::Fin); + drop(channel); self.done = true; + self.credit = None; Ok(()) } @@ -509,6 +554,8 @@ impl poll::SendStream for SendStream { if closed(&self.close).is_none() { channel.abort(End::Reset(code)); } + drop(channel); + self.credit = None; } /// Ready once this side reset the stream, the reader stopped it, or the reader took @@ -542,16 +589,14 @@ pub struct Chunks { /// This side stopped the stream. stopped: bool, /// The open-stream count this stream holds a credit in, until it is done. - credit: Option>, + credit: Option, park: kio::Park, } impl Chunks { - /// Return this stream's credit to its writer's side, once. + /// Let go of this stream's credit, returned to its writer's side once both halves have. fn release(&mut self) { - if let Some(credit) = self.credit.take() { - *credit.lock() -= 1; - } + self.credit = None; } } @@ -796,6 +841,34 @@ mod tests { )); } + /// A bidi stream holds its opener's credit until the peer is done with both halves. + #[test] + fn bi_credit_returns_once_the_peer_is_done_with_both_halves() { + let (mut a, mut b) = pair(Config { + max_concurrent_bi_streams: Some(1), + ..Default::default() + }); + let open = |a: &mut Session, cx: &mut Context<'_>| a.poll_open_bi(cx, Default::default()); + + let (mut send, _recv) = ready(open(&mut a, &mut noop())).unwrap(); + let count = Arc::new(Count::default()); + let waker = Waker::from(count.clone()); + assert!(open(&mut a, &mut Context::from_waker(&waker)).is_pending()); + + // The peer reading our half to the end leaves its own half open. + send.finish().unwrap(); + let (mut peer_send, mut peer_recv) = ready(b.poll_accept_bi(&mut noop())).unwrap(); + assert_eq!(ready(read(&mut peer_recv, usize::MAX)).unwrap(), None); + assert!( + open(&mut a, &mut Context::from_waker(&waker)).is_pending(), + "the peer still writes" + ); + + peer_send.finish().unwrap(); + assert!(count.0.load(Ordering::Relaxed) > 0); + let _second = ready(open(&mut a, &mut noop())).unwrap(); + } + #[test] fn reset_drops_queued_messages() { let (mut a, mut b) = pair(buffer(8)); diff --git a/rs/moq-net/tests/integration/fetch_caps.rs b/rs/moq-net/tests/integration/fetch_caps.rs deleted file mode 100644 index 5cb05f87b3b..00000000000 --- a/rs/moq-net/tests/integration/fetch_caps.rs +++ /dev/null @@ -1,100 +0,0 @@ -#![cfg(feature = "async")] - -//! FETCH caps are charged per peer before shared group requests coalesce. - -use crate::support; - -use std::time::Duration; - -use moq_net::{Hop, Version, session::Limits}; -use support::harness::{MockConnectOptions, connect_mock}; - -const TIMEOUT: Duration = Duration::from_secs(5); - -fn origin(hop: u64) -> moq_net::origin::Producer { - let (origin, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(Hop::new(hop).unwrap())); - support::harness::spawn(driver); - origin -} - -#[moq_clock::test] -async fn an_over_cap_peer_cannot_cancel_another_peers_held_fetch() { - for version in [ - "moq-lite-05", - "moq-lite-06", - "moq-lite-07-wip", - "moq-transport-14", - "moq-transport-16", - "moq-transport-22", - ] { - let version: Version = version.parse().unwrap(); - let publisher = origin(1); - let broadcast = publisher.create_broadcast("room").unwrap(); - let info = moq_net::track::Info::default().with_timescale(None); - let track = broadcast.create_track("video", info.clone()).unwrap(); - let groups = track.dynamic(); - broadcast.announce(Default::default()).unwrap(); - let mut peers = Vec::new(); - for hop in [2, 3] { - let remote = origin(hop); - let mut options = MockConnectOptions::new(version); - options.server_publish = Some(publisher.consume()); - options.client_subscribe = Some(remote.clone()); - let mut limits = Limits::default(); - limits.fetches = 1; - options.server_limits = Some(limits); - let pair = connect_mock(options).await; - let view = moq_clock::timeout(TIMEOUT, remote.consume().routed_broadcast("room")) - .await - .unwrap() - .unwrap(); - peers.push((remote, pair, view)); - } - let mut a = Box::pin(peers[0].2.track("video").unwrap().fetch_group(7, None)); - let request_a = match moq_clock::timeout( - TIMEOUT, - futures::future::select(std::pin::pin!(groups.requested_group()), &mut a), - ) - .await - .unwrap() - { - futures::future::Either::Left((request, _)) => request.unwrap(), - futures::future::Either::Right(_) => panic!("{version}: fetch answered before the publisher"), - }; - let mut b = Box::pin(peers[1].2.track("video").unwrap().fetch_group(8, None)); - let request_b = match moq_clock::timeout( - TIMEOUT, - futures::future::select(std::pin::pin!(groups.requested_group()), &mut b), - ) - .await - .unwrap() - { - futures::future::Either::Left((request, _)) => request.unwrap(), - futures::future::Either::Right(_) => panic!("{version}: fetch answered before the publisher"), - }; - assert_eq!(request_a.sequence(), 7); - assert_eq!(request_b.sequence(), 8); - let extra = peers[0].2.track("video").unwrap().fetch_group(9, None); - let (err, refused) = moq_clock::timeout(TIMEOUT, futures::future::join(peers[0].1.client.closed(), extra)) - .await - .unwrap(); - assert!(refused.is_err()); - assert!( - matches!(err, moq_net::Error::Session(moq_net::SessionError::TooManyRequests)), - "{version}: {err}" - ); - assert!( - request_b.demand().is_used(), - "{version}: the other peer still holds its request" - ); - let mut group = request_b.accept(info).unwrap(); - group.write_frame(None, &b"other peer"[..]).unwrap(); - group.finish().unwrap(); - let mut served = moq_clock::timeout(TIMEOUT, b).await.unwrap().unwrap(); - assert_eq!( - served.read_frame().await.unwrap().unwrap().payload.as_ref(), - b"other peer" - ); - assert!(moq_clock::timeout(TIMEOUT, a).await.unwrap().is_err()); - } -} diff --git a/rs/moq-net/tests/integration/main.rs b/rs/moq-net/tests/integration/main.rs index 7669be7f7b2..33c4011a096 100644 --- a/rs/moq-net/tests/integration/main.rs +++ b/rs/moq-net/tests/integration/main.rs @@ -22,7 +22,6 @@ mod empty_group; mod empty_replacement; mod extensions; mod fetch_cancel; -mod fetch_caps; mod fetch_fanout; mod fetch_from_feed; mod fetch_only; diff --git a/rs/moq-net/tests/integration/request_caps.rs b/rs/moq-net/tests/integration/request_caps.rs index 7f003f97234..ca70c7b092b 100644 --- a/rs/moq-net/tests/integration/request_caps.rs +++ b/rs/moq-net/tests/integration/request_caps.rs @@ -1,9 +1,10 @@ #![cfg(feature = "async")] -//! A server's [`moq_net::session::Limits`] bound what one client can make it hold: a client -//! past a cap loses the session with TOO_MANY_REQUESTS, and on moq-transport drafts 14 to 16 -//! the MAX_REQUEST_ID window they size is granted back as requests close, so a client that -//! keeps opening and closing requests within the caps never stalls. +//! A server bounds what one client can make it hold: flow control bounds its requests, a +//! client past [`moq_net::session::Limits::announces`] loses the session with +//! TOO_MANY_REQUESTS, and on moq-transport drafts 14 to 16 the MAX_REQUEST_ID window the +//! limits size is granted back as requests close, so a client that keeps opening and closing +//! requests within them never stalls. use crate::support; @@ -64,11 +65,10 @@ async fn setup(version: &str, limits: Limits, tracks: usize) -> Setup { } } -fn limits(announces: usize, subscriptions: usize) -> Limits { +fn limits(announces: usize, requests: usize) -> Limits { let mut limits = Limits::default(); limits.announces = announces; - limits.subscriptions = subscriptions; - limits.fetches = 0; + limits.requests = requests; limits } @@ -79,8 +79,8 @@ async fn closed_requests_are_granted_back() { const ROUNDS: usize = 64; for version in VERSIONS { - // A window of 8 requests, far fewer than the rounds below. The cap leaves room - // for an UNSUBSCRIBE still in flight when the next SUBSCRIBE lands. + // A window of 8 requests, far fewer than the rounds below. Doubling the limit leaves + // room for an UNSUBSCRIBE still in flight when the next SUBSCRIBE lands. let setup = setup(version, limits(0, 4), ROUNDS).await; let broadcast = moq_clock::timeout(TIMEOUT, setup.client.consume().routed_broadcast("bcast")) .await @@ -106,38 +106,59 @@ async fn closed_requests_are_granted_back() { } } -/// A subscription past the cap closes the session with TOO_MANY_REQUESTS. +/// With no subscription cap, a client asking for more subscriptions than the server admits +/// still holds no more than the request window (drafts 14 to 16) or the stream credit +/// (moq-lite, draft 17 and later) at once. The rest wait rather than close the session. #[moq_clock::test] -async fn a_subscription_past_the_cap_closes_the_session() { +async fn flow_control_bounds_the_subscriptions_a_peer_holds() { + // A window of 8 requests, and 8 bidi streams toward the server. + const BOUND: usize = 8; + const TRACKS: usize = 3 * BOUND; + for version in VERSIONS { - let setup = setup(version, limits(1, 1), 2).await; - let broadcast = moq_clock::timeout(TIMEOUT, setup.client.consume().routed_broadcast("bcast")) + let version: Version = version.parse().unwrap(); + let server = produce_origin(1); + let client = produce_origin(2); + let broadcast = server.create_broadcast("bcast").unwrap(); + let tracks: Vec<_> = (0..TRACKS) + .map(|i| broadcast.create_track(format!("t{i}"), None).unwrap()) + .collect(); + broadcast.announce(Default::default()).unwrap(); + + let mut options = MockConnectOptions::new(version); + options.transport.max_concurrent_bi_streams = Some(BOUND); + options.server_publish = Some(server.consume()); + options.client_subscribe = Some(client.clone()); + options.server_limits = Some(limits(0, BOUND / 2)); + let pair = connect_mock(options).await; + + let remote = moq_clock::timeout(TIMEOUT, client.consume().routed_broadcast("bcast")) .await .expect("announce timeout") .unwrap(); - - let _held = moq_clock::timeout(TIMEOUT, broadcast.track("t0").unwrap().subscribe(None)) - .await - .expect("subscribe timeout") - .unwrap_or_else(|err| panic!("{version}: the first subscription was refused: {err}")); - - // moq-lite hands the subscriber over once TRACK_INFO answers, so the close - // arrives on the first read instead. - let refused = moq_clock::timeout(TIMEOUT, async { - let mut subscriber = broadcast.track("t1").unwrap().subscribe(None).await?; - subscriber.recv_group().await.map(|_| ()) - }) - .await - .expect("subscribe timeout"); - assert!(refused.is_err(), "{version}: a second subscription was admitted"); - - let err = moq_clock::timeout(TIMEOUT, setup._pair.client.closed()) - .await - .unwrap_or_else(|_| panic!("{version}: the session stayed open")); + let subscribing: Vec<_> = (0..TRACKS) + .map(|i| { + let track = remote.track(&format!("t{i}")).unwrap(); + moq_clock::sim::spawn(async move { + let _subscriber = track.subscribe(None).await; + std::future::pending::<()>().await + }) + }) + .collect(); + moq_clock::sleep(Duration::from_secs(1)).await; + + let held = tracks.iter().filter(|track| track.demand().wanted().is_some()).count(); + assert!(held > 0, "{version}: nothing was subscribed"); + assert!(held <= BOUND, "{version}: the server holds {held} subscriptions"); assert!( - matches!(err, moq_net::Error::Session(moq_net::SessionError::TooManyRequests)), - "{version}: closed with {err}" + moq_clock::timeout(Duration::from_millis(100), pair.client.closed()) + .await + .is_err(), + "{version}: the session closed" ); + for task in subscribing { + task.abort(); + } } } diff --git a/rs/moq-net/tests/integration/track_stream_demand.rs b/rs/moq-net/tests/integration/track_stream_demand.rs index df515800c86..21d941b643d 100644 --- a/rs/moq-net/tests/integration/track_stream_demand.rs +++ b/rs/moq-net/tests/integration/track_stream_demand.rs @@ -294,89 +294,3 @@ async fn bare_handle_is_lazy_through_a_relay() { bare_handle_is_lazy(version, 1).await; } } - -/// Held TRACK streams count against the server's subscription cap, and each SUBSCRIBE -/// takes over its TRACK's place: a client at the cap still subscribes to every track it -/// holds without a demand gap, and one more TRACK closes the session. -#[moq_clock::test] -async fn held_tracks_share_the_cap_with_their_subscriptions() { - const CAP: usize = 3; - - for version in VERSIONS { - let version: Version = version.parse().unwrap(); - let server = produce_origin(1); - let client = produce_origin(2); - - let broadcast = server.create_broadcast("room").unwrap(); - let mut tracks = Vec::new(); - for i in 0..=CAP { - let track = broadcast.create_track(format!("t{i}"), timed()).unwrap(); - let mut group = track.append_group().unwrap(); - group.write_frame(Timestamp::ZERO, b"key".as_ref()).unwrap(); - let edges = record_track!(track.demand()); - tracks.push((track, group, edges)); - } - broadcast.announce(Default::default()).unwrap(); - - let mut options = MockConnectOptions::new(version); - options.server_publish = Some(server.consume()); - options.client_subscribe = Some(client.clone()); - options.latency = LATENCY; - let mut limits = moq_net::session::Limits::default(); - limits.subscriptions = CAP; - options.server_limits = Some(limits); - let pair = connect_mock(options).await; - - let remote = moq_clock::timeout(TIMEOUT, client.consume().routed_broadcast("room")) - .await - .expect("announce timeout") - .unwrap(); - - // A held query keeps each track wanted, and so its TRACK stream open. - let mut held = Vec::new(); - for i in 0..CAP { - let track = remote.track(&format!("t{i}")).unwrap(); - let mut query = track.query(); - moq_clock::timeout(TIMEOUT, &mut query) - .await - .unwrap_or_else(|_| panic!("{version}: t{i} info stalled")) - .unwrap_or_else(|err| panic!("{version}: t{i} info refused: {err}")); - held.push((track, query)); - } - moq_clock::sleep(Duration::from_secs(1)).await; - for (i, (.., edges)) in tracks.iter().enumerate().take(CAP) { - assert_eq!(*edges.borrow(), [true], "{version}: t{i} is not held"); - } - - let mut subscribers = Vec::new(); - for (i, (track, _)) in held.iter().enumerate() { - let mut subscriber = moq_clock::timeout(TIMEOUT, track.subscribe(None)) - .await - .unwrap_or_else(|_| panic!("{version}: t{i} subscribe stalled")) - .unwrap_or_else(|err| panic!("{version}: t{i} refused at the cap: {err}")); - moq_clock::timeout(TIMEOUT, subscriber.recv_group()) - .await - .unwrap_or_else(|_| panic!("{version}: t{i} delivered nothing")) - .unwrap() - .expect("the track is live"); - subscribers.push(subscriber); - } - moq_clock::sleep(Duration::from_secs(1)).await; - for (i, (.., edges)) in tracks.iter().enumerate().take(CAP) { - assert_eq!(*edges.borrow(), [true], "{version}: t{i} demand"); - } - - // The subscriptions alone fill the cap now. - let refused = moq_clock::timeout(TIMEOUT, remote.track(&format!("t{CAP}")).unwrap().query()) - .await - .expect("info timeout"); - assert!(refused.is_err(), "{version}: one more TRACK was admitted"); - let err = moq_clock::timeout(TIMEOUT, pair.client.closed()) - .await - .unwrap_or_else(|_| panic!("{version}: the session stayed open")); - assert!( - matches!(err, moq_net::Error::Session(moq_net::SessionError::TooManyRequests)), - "{version}: closed with {err}" - ); - } -} diff --git a/rs/moq-relay/src/cluster.rs b/rs/moq-relay/src/cluster.rs index d2017d9f11e..8d34ffd7655 100644 --- a/rs/moq-relay/src/cluster.rs +++ b/rs/moq-relay/src/cluster.rs @@ -2352,17 +2352,11 @@ mod tests { async fn request_limits_follow_the_admitted_grant() { let mut options = Options::default(); options.session.announces = 2; - options.session.subscriptions = 3; - options.session.fetches = 4; + options.session.requests = 3; options.peer.announces = 20; - options.peer.subscriptions = 30; - options.peer.fetches = 40; + options.peer.requests = 30; let cluster = Cluster::new(options).unwrap(); - for (peer, upstream, expected) in [ - (false, false, (2, 3, 4)), - (true, false, (20, 30, 40)), - (true, true, (20, 30, 40)), - ] { + for (peer, upstream, expected) in [(false, false, (2, 3)), (true, false, (20, 30)), (true, true, (20, 30))] { let mut grant = moq_auth::Grant::new(moq_auth::Patterns::new(), moq_auth::Patterns::new()); grant.peer = peer; grant.upstream = upstream; @@ -2370,7 +2364,7 @@ mod tests { // A cluster-looking path alone never selects the peer policy. let lease = auth::Lease::new("/.cluster/untrusted", consumer); let limits = cluster.limits(&lease); - assert_eq!((limits.announces, limits.subscriptions, limits.fetches), expected); + assert_eq!((limits.announces, limits.requests), expected); } } diff --git a/rs/moq-relay/src/config.rs b/rs/moq-relay/src/config.rs index 49b1a080aa7..f5756fbb320 100644 --- a/rs/moq-relay/src/config.rs +++ b/rs/moq-relay/src/config.rs @@ -419,11 +419,9 @@ mod tests { fn session_limits_merge_without_crossing_peer_policy() { if !test_env::Env::without(&[ "MOQ_SESSION_ANNOUNCES", - "MOQ_SESSION_SUBSCRIPTIONS", - "MOQ_SESSION_FETCHES", - "MOQ_PEER_FETCHES", + "MOQ_SESSION_REQUESTS", "MOQ_PEER_ANNOUNCES", - "MOQ_PEER_SUBSCRIPTIONS", + "MOQ_PEER_REQUESTS", ]) .isolate() { @@ -433,31 +431,25 @@ mod tests { let path = dir.path().join("limits.toml"); std::fs::write( &path, - "[session]\nannounces = 7\nsubscriptions = 8\nfetches = 9\n[peer]\nannounces = 90\nsubscriptions = 91\nfetches = 92\n", + "[session]\nannounces = 7\nrequests = 8\n[peer]\nannounces = 90\nrequests = 91\n", ) .unwrap(); let config = Config::parse_and_merge([std::ffi::OsString::from("moq-relay"), path.clone().into()]).unwrap(); assert_eq!(config.session.resolve().announces, 7); - assert_eq!(config.session.resolve().subscriptions, 8); + assert_eq!(config.session.resolve().requests, 8); assert_eq!(config.peer.resolve().announces, 90); - assert_eq!(config.peer.resolve().subscriptions, 91); - assert_eq!(config.session.resolve().fetches, 9); - assert_eq!(config.peer.resolve().fetches, 92); + assert_eq!(config.peer.resolve().requests, 91); let config = Config::parse_and_merge([ std::ffi::OsString::from("moq-relay"), path.into(), "--session-announces=0".into(), - "--peer-subscriptions=1000".into(), - "--session-fetches=0".into(), - "--peer-fetches=2000".into(), + "--peer-requests=1000".into(), ]) .unwrap(); assert_eq!(config.session.resolve().announces, 0); - assert_eq!(config.session.resolve().subscriptions, 8); + assert_eq!(config.session.resolve().requests, 8); assert_eq!(config.peer.resolve().announces, 90); - assert_eq!(config.peer.resolve().subscriptions, 1000); - assert_eq!(config.session.resolve().fetches, 0); - assert_eq!(config.peer.resolve().fetches, 2000); + assert_eq!(config.peer.resolve().requests, 1000); } /// `[peer.quic]` mirrors `[quic]`'s keys without touching `[quic]` itself. diff --git a/rs/moq-relay/src/limits.rs b/rs/moq-relay/src/limits.rs index 2ae1946be96..dba45b090ea 100644 --- a/rs/moq-relay/src/limits.rs +++ b/rs/moq-relay/src/limits.rs @@ -1,9 +1,9 @@ -//! Request caps and QUIC limits selected after the relay authorizes a session. +//! Session limits and QUIC limits selected after the relay authorizes a session. use anyhow::Context; use serde::{Deserialize, Serialize}; -/// Request caps for ordinary client sessions. +/// Session limits for ordinary client sessions. #[derive(usage_rs::Args, Clone, Debug, Deserialize, Serialize)] #[serde(default, deny_unknown_fields)] #[non_exhaustive] @@ -16,41 +16,32 @@ pub struct Session { setting = "session.announces" )] pub announces: usize, - /// Maximum simultaneously held subscriptions. + /// Maximum other simultaneously held moq-transport requests, sizing the drafts 14 to 16 request window. #[usage( - long = "session-subscriptions", - env = "MOQ_SESSION_SUBSCRIPTIONS", - default = "1000", - setting = "session.subscriptions" - )] - pub subscriptions: usize, - /// Maximum simultaneously held FETCH requests. - #[usage( - long = "session-fetches", - env = "MOQ_SESSION_FETCHES", + long = "session-requests", + env = "MOQ_SESSION_REQUESTS", default = "10000", - setting = "session.fetches" + setting = "session.requests" )] - pub fetches: usize, + pub requests: usize, } impl Default for Session { fn default() -> Self { Self { announces: 1000, - subscriptions: 1000, - fetches: 10000, + requests: 10000, } } } impl Session { pub(crate) fn resolve(&self) -> moq_net::session::Limits { - resolve(self.announces, self.subscriptions, self.fetches) + resolve(self.announces, self.requests) } } -/// Request caps and QUIC limits for authenticated cluster peer sessions. +/// Session limits and QUIC limits for authenticated cluster peer sessions. #[derive(usage_rs::Args, Clone, Debug, Deserialize, Serialize)] #[serde(default, deny_unknown_fields)] #[non_exhaustive] @@ -63,22 +54,14 @@ pub struct Peer { setting = "peer.announces" )] pub announces: usize, - /// Maximum simultaneously held subscriptions. + /// Maximum other simultaneously held moq-transport requests, sizing the drafts 14 to 16 request window. #[usage( - long = "peer-subscriptions", - env = "MOQ_PEER_SUBSCRIPTIONS", - default = "10000", - setting = "peer.subscriptions" - )] - pub subscriptions: usize, - /// Maximum simultaneously held FETCH requests. - #[usage( - long = "peer-fetches", - env = "MOQ_PEER_FETCHES", - default = "10000", - setting = "peer.fetches" + long = "peer-requests", + env = "MOQ_PEER_REQUESTS", + default = "20000", + setting = "peer.requests" )] - pub fetches: usize, + pub requests: usize, /// QUIC limits a peer session widens to (`[peer.quic]`). #[usage(flatten)] pub quic: Quic, @@ -88,8 +71,7 @@ impl Default for Peer { fn default() -> Self { Self { announces: 100000, - subscriptions: 10000, - fetches: 10000, + requests: 20000, quic: Quic::default(), } } @@ -97,7 +79,7 @@ impl Default for Peer { impl Peer { pub(crate) fn resolve(&self) -> moq_net::session::Limits { - resolve(self.announces, self.subscriptions, self.fetches) + resolve(self.announces, self.requests) } } @@ -172,10 +154,9 @@ impl Quic { } } -fn resolve(announces: usize, subscriptions: usize, fetches: usize) -> moq_net::session::Limits { +fn resolve(announces: usize, requests: usize) -> moq_net::session::Limits { let mut limits = moq_net::session::Limits::default(); limits.announces = announces; - limits.subscriptions = subscriptions; - limits.fetches = fetches; + limits.requests = requests; limits } diff --git a/rs/moq-relay/src/settings.rs b/rs/moq-relay/src/settings.rs index 1a773114ade..232dadb2a60 100644 --- a/rs/moq-relay/src/settings.rs +++ b/rs/moq-relay/src/settings.rs @@ -251,10 +251,8 @@ struct Internal { struct Session { #[usage(env = "MOQ_SESSION_ANNOUNCES", cli("--session-announces"))] announces: Option, - #[usage(env = "MOQ_SESSION_SUBSCRIPTIONS", cli("--session-subscriptions"))] - subscriptions: Option, - #[usage(env = "MOQ_SESSION_FETCHES", cli("--session-fetches"))] - fetches: Option, + #[usage(env = "MOQ_SESSION_REQUESTS", cli("--session-requests"))] + requests: Option, } #[derive(usage_rs::Config)] @@ -262,10 +260,8 @@ struct Session { struct Peer { #[usage(env = "MOQ_PEER_ANNOUNCES", cli("--peer-announces"))] announces: Option, - #[usage(env = "MOQ_PEER_SUBSCRIPTIONS", cli("--peer-subscriptions"))] - subscriptions: Option, - #[usage(env = "MOQ_PEER_FETCHES", cli("--peer-fetches"))] - fetches: Option, + #[usage(env = "MOQ_PEER_REQUESTS", cli("--peer-requests"))] + requests: Option, #[usage(flatten)] quic: PeerQuic, } diff --git a/rs/moq-tokio/src/client.rs b/rs/moq-tokio/src/client.rs index 87f188bc319..f3776825eba 100644 --- a/rs/moq-tokio/src/client.rs +++ b/rs/moq-tokio/src/client.rs @@ -206,7 +206,7 @@ impl Client { self } - /// Cap the announcements and subscriptions this peer can hold on a session. + /// Bound what this peer can make a session hold beyond flow control. pub fn with_limits(mut self, limits: moq_net::session::Limits) -> Self { self.moq = self.moq.with_limits(limits); self