diff --git a/quest/m2/api-shape/README.md b/quest/m2/api-shape/README.md deleted file mode 100644 index d0ac6f21b88..00000000000 --- a/quest/m2/api-shape/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Small API fixes before the cut - -## Goal - -The surfaces `main` adds since `release` follow the repository's API rules -before the cut publishes them. The epic's own pre-cut deletion sweep landed in -[moq-dev/moq#8461](https://github.com/moq-dev/moq/pull/8461); it finishes with -its remaining children. - -## Plan - -Rules every child follows: - -- Removal beats addition. A public item with no caller in this repository - or a known downstream application is deleted, unless an m1 or m2 quest plans a - caller; it goes private only when internal code still uses it. -- No serde aliases, refusals, or shims for a spelling `release` never - shipped. -- Each child lists its public API and wire impact in its PR, and its Impact - section says how to migrate. diff --git a/quest/m2/api-shape/request-expired.md b/quest/m2/api-shape/request-expired.md deleted file mode 100644 index 145e821f5cd..00000000000 --- a/quest/m2/api-shape/request-expired.md +++ /dev/null @@ -1,26 +0,0 @@ -# [S] moq-tokio's Request takes no future - -## Goal - -`moq_tokio::server::Request` takes no future: `within(work)` is replaced by -`poll_expired`/`expired()`, which resolves once the accept deadline passes, -having refused the session with the timeout code, mirroring moq-net's -`Handshake::poll_expired` (`rs/moq-net/src/server.rs:1218`). moq-cli -(`main.rs:180`) and moq-relay race their admission against it, and -moq-relay's `incoming::Sealed` (`incoming.rs:116`) swaps `within` for -`expired`, so the tokio and io_uring paths (`incoming.rs:259-268`, -`uring.rs:827`) share one race in `connection.rs`. -The same PR rewrites every other `within` reference: the -`rs/moq-tokio/CHANGELOG.md` Unreleased entry, the `rs/moq-relay/MIGRATE.md` -Unreleased note, and the intra-doc link in `rs/moq-relay/src/auth.rs` -(`Auth::admit` docs), which otherwise fails `cargo doc -D warnings`. -Public API: `Request::within` removed, `Request::poll_expired`/`expired` -added; neither is on `release`. Wire: none. - -## Plan - -Decided 2026-11-11 (maintainer, rust2 /quest-unblock): callbacks and future -parameters are avoided where a closure-free API exists; the other seven -future- or closure-taking kio and moq-tokio helpers have none (`timeout` -already has `sleep_until`, `drive` has `time::run`, `wait` has `Pending`), -so they stay. diff --git a/quest/m3/release/api-review.md b/quest/m3/release/api-review.md index 46161e05969..d826f0b24b7 100644 --- a/quest/m3/release/api-review.md +++ b/quest/m3/release/api-review.md @@ -39,7 +39,7 @@ consumers in this repository and its downstream applications. Mean 6.9; three clusters were restrictive (the native playout clock, JS duration units, and moq-video's environment knobs). Its approved changes are m2 quests (route-roles, js-time-types, mux-sync, no-sentinels, video-devices, -gateway-ingest (landed), and the [api-shape epic](/quest/m2/api-shape/README.md)), +gateway-ingest (landed), and the api-shape epic (landed)), two m1 quests, and plan edits. Check first, next run: surfaces `just api-diff` cannot see (GStreamer properties, CLI flags and env, MIGRATE drift) and publish versions of packages exempt from the cut's version. `just diff --git a/rs/moq-cli/src/main.rs b/rs/moq-cli/src/main.rs index 72d0c7d96bc..f2a782fbacf 100644 --- a/rs/moq-cli/src/main.rs +++ b/rs/moq-cli/src/main.rs @@ -175,12 +175,16 @@ impl Serving { let origin = &self.cluster.origin; let directions = self.directions; let auth_request = moq_relay::auth::request_for(&self.auth, &request); - // The listener's handshake deadline covers admission; `within` closes a session + // The listener's handshake deadline covers admission; `expired` closes a session // it gives up on with the timeout code. - let lease = match request.within(self.auth.admit(auth_request)).await { - Err(err) => return Err(anyhow::Error::new(err).context("admission timed out")), - Ok(Ok(lease)) => lease, - Ok(Err(err)) => { + let admitted = tokio::select! { + biased; + admitted = self.auth.admit(auth_request) => admitted, + () = request.expired() => return Err(anyhow::Error::new(moq_net::Error::Timeout).context("admission timed out")), + }; + let lease = match admitted { + Ok(lease) => lease, + Err(err) => { request.reject(moq_net::SessionError::from(&err)).await.ok(); return Err(anyhow::Error::new(err).context("session refused")); } diff --git a/rs/moq-relay/src/auth.rs b/rs/moq-relay/src/auth.rs index 1fb03818983..b8e469946a5 100644 --- a/rs/moq-relay/src/auth.rs +++ b/rs/moq-relay/src/auth.rs @@ -959,7 +959,7 @@ impl Auth { /// /// Waits on the decider for as long as the caller does. The caller owns the /// deadline: a listener bounds it with the connection's handshake deadline - /// ([`moq_tokio::server::Request::within`]), and dropping the future withdraws + /// ([`moq_tokio::server::Request::expired`]), and dropping the future withdraws /// the admission from the decider. /// /// A path naming a `.` or `..` segment is refused before the decider sees it. A diff --git a/rs/moq-relay/src/connection.rs b/rs/moq-relay/src/connection.rs index 7adf63cb1c6..ee68dfaece6 100644 --- a/rs/moq-relay/src/connection.rs +++ b/rs/moq-relay/src/connection.rs @@ -115,11 +115,14 @@ impl Connection { // socket like it bounds a session, and at the handshake deadline, so a peer // cannot hold the connection open behind a decision that never comes. // Boxed: the admission future is large, and nesting it inline overflows debug stacks. - let admitted = request - .within(Box::pin(lifecycle.on(shared.as_ref(), admit))) - .await - .inspect_err(|_| lifecycle.cluster.refusals.record(RefusalKind::Unavailable)) - .map_err(|err| err.context("admission timed out"))??; + let admitted = tokio::select! { + biased; + admitted = Box::pin(lifecycle.on(shared.as_ref(), admit)) => admitted?, + () = request.expired() => { + lifecycle.cluster.refusals.record(RefusalKind::Unavailable); + return Err(anyhow::Error::new(moq_net::Error::Timeout).context("admission timed out")); + } + }; let (admitted, registration) = match admitted { Ok(admitted) => admitted, Err(err) => { diff --git a/rs/moq-relay/src/incoming.rs b/rs/moq-relay/src/incoming.rs index 567bf0f942c..aef9192dbe4 100644 --- a/rs/moq-relay/src/incoming.rs +++ b/rs/moq-relay/src/incoming.rs @@ -62,8 +62,9 @@ pub trait Sealed: Sized { /// What the auth decider is asked about this session. fn admission(&self, auth: &auth::Auth) -> moq_auth::Request; - /// Finish `work` before the handshake deadline, closing the session if it passes. - async fn within(&mut self, work: impl std::future::Future) -> anyhow::Result; + /// Resolve once the handshake deadline passes, having closed the session with the + /// timeout code; never, without a deadline. + async fn expired(&mut self); /// Refuse the session, closing it with `code`. async fn reject(self, code: moq_net::SessionError); @@ -113,8 +114,8 @@ impl Sealed for moq_tokio::server::Request { auth::request_for(auth, self) } - async fn within(&mut self, work: impl std::future::Future) -> anyhow::Result { - Ok(moq_tokio::server::Request::within(self, work).await?) + async fn expired(&mut self) { + moq_tokio::server::Request::expired(self).await } async fn reject(self, code: moq_net::SessionError) { @@ -198,8 +199,8 @@ impl Sealed for Accepted { auth::request_for_setup(auth, &self.handshake, self.transport) } - async fn within(&mut self, work: impl std::future::Future) -> anyhow::Result { - within(&mut self.handshake, work).await + async fn expired(&mut self) { + self.handshake.expired().await } async fn reject(self, code: moq_net::SessionError) { @@ -253,16 +254,3 @@ impl Sealed for Accepted { Ok(()) } } - -/// Finish `work` before `handshake`'s accept deadline, which refuses the session if it passes. -#[cfg(any(feature = "test-support", all(target_os = "linux", feature = "_uring")))] -pub(crate) async fn within( - handshake: &mut moq_net::server::Handshake, - work: impl std::future::Future, -) -> anyhow::Result { - let expired = handshake.expired(); - match futures::future::select(std::pin::pin!(work), std::pin::pin!(expired)).await { - futures::future::Either::Left((done, _)) => Ok(done), - futures::future::Either::Right(_) => Err(moq_net::Error::Timeout.into()), - } -} diff --git a/rs/moq-relay/src/uring.rs b/rs/moq-relay/src/uring.rs index b669a27b013..0896bdfaf38 100644 --- a/rs/moq-relay/src/uring.rs +++ b/rs/moq-relay/src/uring.rs @@ -824,8 +824,8 @@ impl crate::incoming::Sealed for Request { request } - async fn within(&mut self, work: impl Future) -> anyhow::Result { - crate::incoming::within(&mut self.handshake, work).await + async fn expired(&mut self) { + self.handshake.expired().await } async fn reject(self, code: moq_net::SessionError) { diff --git a/rs/moq-tokio/CHANGELOG.md b/rs/moq-tokio/CHANGELOG.md index 00a372c38f8..f677d756bf0 100644 --- a/rs/moq-tokio/CHANGELOG.md +++ b/rs/moq-tokio/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `server::Request::with_quic_limits` sets the QUIC limits `ok` applies before answering SETUP. A server QUIC connection holds only `moq_net::transport::SETUP_RECEIVE_WINDOW` until `ok` opens `[quic] receive_window`, so a client cannot bank credit before it is admitted. -- `server::Request::within` finishes a future, such as admitting the session, within what remains of the handshake deadline, closing the session with the timeout code otherwise. +- `server::Request::poll_expired` and `expired` resolve once the handshake deadline passes, having closed the session with the timeout code, so a caller races admission against them. ## [0.19.23](https://github.com/moq-dev/moq/compare/moq-tokio-v0.19.22...moq-tokio-v0.19.23) - 2026-10-06 diff --git a/rs/moq-tokio/src/server.rs b/rs/moq-tokio/src/server.rs index 19684b2fe11..bc429ec99f3 100644 --- a/rs/moq-tokio/src/server.rs +++ b/rs/moq-tokio/src/server.rs @@ -1633,23 +1633,18 @@ impl Request { Ok(self) } - /// Finish `work` before the accept deadline, or refuse the session with the timeout code - /// and return [`moq_net::Error::Timeout`]; see [`moq_net::server::Handshake::expired`]. + /// Resolve once the accept deadline passes, having refused the session with the timeout + /// code; never, without a deadline. See [`moq_net::server::Handshake::poll_expired`]. /// - /// Admitting the session is the caller's part of the handshake, so the same - /// `listen.timeout` that bounds the transport and SETUP bounds it too; a peer - /// cannot hold a connection open behind a decision that never comes. Without a - /// deadline, waits forever. - pub async fn within(&mut self, work: impl Future) -> crate::Result { - let handshake = &mut self.handshake; - crate::runtime::scope(async move { - tokio::select! { - biased; - done = work => Ok(done), - () = handshake.expired() => Err(moq_net::Error::Timeout.into()), - } - }) - .await + /// Race admission against it, so the same `listen.timeout` that bounds the transport and + /// SETUP bounds the caller's decision too: a peer cannot hold a connection open behind a + /// decision that never comes. Once it resolves, [`ok`](Self::ok) fails with the timeout. + #[kio::wrapper] + pub fn poll_expired(&mut self, waiter: &kio::Waiter) -> std::task::Poll<()> { + // The deadline's timer may start here, which needs a tokio runtime even when an + // embedder polls from outside one. + let _runtime = crate::runtime::enter(); + self.handshake.poll_expired(waiter) } /// The receive window of the qmux session under this request. @@ -2238,6 +2233,49 @@ mod tests { assert!(admission.close().now_or_never().is_some()); } + /// An embedder may poll the deadline from outside any tokio runtime. A SETUP that is + /// already buffered resolves the handshake before its timer starts, so the timer + /// first starts here and still needs a runtime. + #[cfg(feature = "websocket")] + #[test] + fn expired_polls_outside_a_runtime() { + use moq_net::transport::poll::{SendOptions, SendStream as _, Session as _}; + let runtime = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .unwrap(); + let admission = moq_net::server::Admission::default(); + let (mut request, _client) = runtime.block_on(async { + let (client, server) = session_pair().await; + let mut setup = client.open_uni(SendOptions::default()).await.unwrap(); + assert_eq!(setup.write(&[1, 1, 0]).await.unwrap(), 3); + setup.finish().unwrap(); + // Let the in-memory pumps deliver the SETUP before the handshake's first poll. + for _ in 0..100 { + tokio::task::yield_now().await; + } + let handshake = moq_net::Server::new() + .with_timeout(Some(std::time::Duration::from_secs(60))) + .accept_request(moq_net::time::Instant::now(), server) + .await + .expect("a buffered SETUP"); + let request = Request { + active: admission.enter().unwrap(), + transport: Transport::WebSocket, + url: None, + authority: None, + identity: None, + link: Link::default(), + handshake: Box::new(handshake), + under: Under::Opaque, + quic_limits: Default::default(), + }; + (request, client) + }); + assert!(tokio::runtime::Handle::try_current().is_err()); + assert!(request.poll_expired(&kio::Waiter::noop()).is_pending()); + } + #[cfg(feature = "websocket")] #[tokio::test(start_paused = true)] async fn upgraded_websocket_refuses_setup_path_presence() {