diff --git a/doc/bin/cli.md b/doc/bin/cli.md index 3f6abf1bf12..ffd93532706 100644 --- a/doc/bin/cli.md +++ b/doc/bin/cli.md @@ -69,7 +69,7 @@ none and are closed the same way. A second signal exits immediately; `--drain-timeout 0s` closes sessions immediately. Pending handshakes and admission requests share the same drain window, and an open stdin pipe does not keep the process alive afterward. Admission is part of -the handshake, so `--listen-timeout` bounds it too; `0s` leaves admission without +the handshake, so `--listen-timeout` (default `30s`) bounds it too; `0s` leaves admission without a deadline. `moq import --help` lists the sources and `moq import rtmp --help` a specific diff --git a/doc/bin/relay/config.md b/doc/bin/relay/config.md index e7ef6ef3d57..3cef62e66aa 100644 --- a/doc/bin/relay/config.md +++ b/doc/bin/relay/config.md @@ -18,7 +18,7 @@ Precedence is CLI, then env, then file, then defaults. [listen] bind = "[::]:443" # QUIC (UDP), as --listen. Omit for a stream-only relay. version = ["moq-lite-05"] # Restrict accepted versions. Omit for all but moq-lite-07-wip. -timeout = "10s" # Handshake deadline. "0" waits forever. +timeout = "30s" # Handshake deadline. "0" waits forever. [listen.reset] secret = "/etc/moq/reset.key" # File holding 64 hex chars. Omit for a random key. diff --git a/doc/lib/rs/moq-net.md b/doc/lib/rs/moq-net.md index 1aca55c6077..b69a792c40f 100644 --- a/doc/lib/rs/moq-net.md +++ b/doc/lib/rs/moq-net.md @@ -28,7 +28,7 @@ What you use it for, beyond what the concept page already describes: - **End content by finishing tracks.** A broadcast has no finished state. When the input ends, finish each track: `finish(self)` consumes the producer and returns a `track::Finished`, which can still take an older group below the end, be read, or be aborted, but not append. Hold it, and the broadcast stays announced and keeps serving the track until you close it or drop its route; dropping the last handle releases the track, so new readers no longer find it. How long to keep it up for late readers is yours to decide: `moq_mux::Linger` holds a hang broadcast for a fixed window. Ending a group returns a `group::Finished`, which can be read or aborted to release its cache: `finish(end)` ends it whole where its content stops, so a reader can tell the group starting there continues it, and `close()` ends it without one. - **Demand says whether anyone is watching.** `demand()` on a track, group, or broadcast says whether a subscriber is attached. First-party capture does not wait for it: video encodes while enabled and audio keeps raw PCM to encode when someone listens, so a late subscription's `delay.max` or a FETCH finds the recent past. Demand gates bandwidth reservations, transcode rungs, and on-demand video where a publisher opts in, which saves the encode but leaves nothing from before the first subscriber. 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. Demand rolls up: a frame being read keeps its group wanted, a group a subscription or fetch handed out keeps its track wanted until read to its end, and any wanted track keeps its broadcast wanted. - **Use the model without a runtime.** By default `moq-net` is its `poll_*` APIs and origin driver with caller-supplied time. The `async` feature adds their async wrappers, `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. `moq-tokio` hides 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. `Server` bounds each accept with one deadline (10 s by default, `with_timeout`) across SETUP, your admission decision (`Handshake::expired`), and moq-lite 01/02's SETUP reply, and opens a receive window the transport held back once you admit (`with_receive_window`). +- **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. `moq-tokio` hides 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. `Server` bounds each accept with one deadline from the connection's arrival (30 s by default, `with_timeout`), across your transport handshake (`Server::deadline`), SETUP, your admission decision (`Handshake::expired`), and moq-lite 01/02's SETUP reply, and opens a receive window the transport held back once you admit (`with_receive_window`). - **Reconnect policy comes with it.** With the `async` feature, `moq_net::Reconnect` decides which of a peer's addresses to dial, how long each dial and handshake may take, when to back off and give up, and how to follow a GOAWAY, without doing I/O: you dial each `Attempt` it asks for and report back. `moq-tokio`'s `Connection` runs it, so a client on another runtime gets the same policy rather than a copy. The first walk of the peer's addresses fails fast: if it yields no session, the policy ends with that walk's error instead of retrying, so a setup mistake such as an untrusted certificate or no version in common surfaces at once, and a client started before its relay is reachable exits for its supervisor to restart. Once a session has been established, later failures back off and retry, so relay restarts still recover. - **A session bounds what its peer can hold.** Each request holds a stream, so the transport's stream credit bounds subscriptions and FETCHes. Once that credit runs out, a waiting open resets the lowest-priority group stream below it, which the subscriber sees dropped, so the credit it frees goes to the higher-priority group. `session::Limits` (via `Client::with_limits` and `Server::with_limits`) bounds the announcements per session. The default suits a relay mesh, so lower it for untrusted peers. Past it, the session closes with `TOO_MANY_REQUESTS`. Peer-declared lengths are capped before they are buffered. - **Authorization is in band.** On moq-lite 07 (`moq-lite-07-wip`, opt-in), `session.auth()` presents tokens without reconnecting and watches the grant the peer sent back. `add(token)` presents another and returns its `Credential` at once, and `credential.answered().await` waits for the peer to take it: on its AUTH stream, or at once on moq-transport without AUTH, where only a request that names it carries it. Dropping its last clone, including any a route holds, withdraws it, answered or not. A handle passed to `Client::with_auth` outlives each session, so its tokens, and the routes naming them, carry across your own reconnects. A server verifies tokens itself by taking `handshake.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. diff --git a/quest/m1/relay-accept-deadline.md b/quest/m1/relay-accept-deadline.md deleted file mode 100644 index 765cc7cfe41..00000000000 --- a/quest/m1/relay-accept-deadline.md +++ /dev/null @@ -1,38 +0,0 @@ -# [S] A relay's accept deadline outlasts a client's handshake backoff - -## Goal - -A relay keeps a client on a bad network long enough to finish its QUIC -handshake under the QUIC Interop Runner's 30% loss, so `--listen-timeout` -does not shed the clients moq-quic's own handshake timeout now keeps. - -## Plan - -Found by [the handshake loss quest](https://github.com/moq-dev/moq/pull/8824), -which raised moq-quic's `handshake_timeout` to 30 s, an inactivity bound. -`moq_net::server::DEFAULT_TIMEOUT` (10 s), which `moq-tokio`'s -`listen.timeout` and so the relay's `--listen-timeout` default to, is a total -deadline from the connection's arrival. It covers the QUIC handshake, the -client's SETUP, and the caller's admission, and for moq-lite 01/02, whose -server SETUP waits on `ok()`, the reply too; every other version sends its -reply from the started session, outside the deadline. Under the QUIC Interop -Runner's 30% loss a client's probe gaps alone reach 13 s, so this deadline -still drops it. - -Decided 2026-11-15 (maintainer, /quest-complete): raise the default to 30 s -(rejected: keep 10 s), the same as `moq-tokio`'s connect timeout on the client -side, and update `doc/bin/relay/config.md`, `doc/bin/cli.md`, and -`doc/lib/rs/moq-net.md`. - -A total deadline is not an inactivity bound: a client that keeps making -progress but needs more than 30 s overall, such as one configured with a -handshake timeout above 30 s and hitting several long gaps, is still shed. -That is the intended trade: past 30 s the client's own connect timeout gives -up too. - -Nothing else bounds a half-open session: `Admission` only counts active -connections for draining and caps none, so this deadline is the whole bound on -how long each one holds its slot, now up to three times longer. - -Public API: the default of `moq_net::Server::with_timeout` and `--listen-timeout`, -a behavior change. Wire: none. diff --git a/rs/moq-net/src/server.rs b/rs/moq-net/src/server.rs index 715507d5cd9..1856657c471 100644 --- a/rs/moq-net/src/server.rs +++ b/rs/moq-net/src/server.rs @@ -83,9 +83,10 @@ impl Drop for Admitted { } } -/// How long [`Server`] gives a connection to be accepted, from its arrival through the SETUP -/// reply, unless [`Server::with_timeout`] says otherwise. -pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(10); +/// How long [`Server`] gives a connection to be accepted, from its arrival through admission, +/// unless [`Server::with_timeout`] says otherwise. Matches a client's connect timeout, so a +/// client whose handshake probes back off under heavy loss is not shed first. +pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(30); /// A MoQ server session builder. #[derive(Clone)] diff --git a/rs/moq-tokio/src/listen.rs b/rs/moq-tokio/src/listen.rs index 11495adff17..7a2fa1b8ebf 100644 --- a/rs/moq-tokio/src/listen.rs +++ b/rs/moq-tokio/src/listen.rs @@ -153,7 +153,7 @@ pub struct Config { /// Maximum time for one accepted connection to finish its handshake: the /// QUIC, WebTransport, WebSocket, or qmux one, then the MoQ SETUP, whatever the /// server runs under (admission, say), until the session is accepted. Defaults to - /// 10 seconds; set to 0 to wait forever. + /// 30 seconds; set to 0 to wait forever. /// /// A peer that connects and then never speaks would otherwise hold its /// connection open indefinitely, since keep-alives count as activity. The diff --git a/rs/moq-tokio/src/websocket.rs b/rs/moq-tokio/src/websocket.rs index b1090e6f999..4c6e326915e 100644 --- a/rs/moq-tokio/src/websocket.rs +++ b/rs/moq-tokio/src/websocket.rs @@ -1326,8 +1326,16 @@ mod timeout_tests { let _stream = kio::wait(|waiter| peer.poll_open_bi(waiter, Default::default())) .await .unwrap(); - tokio::time::advance(timeout.unwrap_or(crate::listen::DEFAULT_TIMEOUT)).await; - let result = accept.as_mut().now_or_never(); + // Step a second at a time so QMux keep-alives flow as on a live link: one jump + // past their 30s deadline would close the session without a ping. + let mut result = None; + for _ in 0..timeout.unwrap_or(crate::listen::DEFAULT_TIMEOUT).as_secs() { + tokio::time::advance(time::Duration::from_secs(1)).await; + result = accept.as_mut().now_or_never(); + if result.is_some() { + break; + } + } if expires { assert!( matches!(result, Some(Err(crate::Error::MoqNet(moq_net::Error::Timeout)))),