From 9383f675c4866d47e855ae82bef08c43712ffd4f Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 22 Oct 2026 16:41:22 -0700 Subject: [PATCH 1/5] chore(quest): claim quest/m1/uring-mtu.md Quest-Claim: b9932b2c63486756 From 9b6b466b0e823c0b83424d6c498322458b5f85d7 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 22 Oct 2026 14:53:04 -0700 Subject: [PATCH 2/5] fix(uring): a failed send costs its packet, not the socket Every send error but ECONNREFUSED, an unreachable destination, and the GSO fallback failed the io_uring socket for good, and with it every connection its worker serves. EPERM is the realistic trigger: a netfilter drop or a full conntrack table, which a spoofed-source flood can fill. Classify by errno: unreachable stays per destination; EBADF, ENOTSOCK and EFAULT, which mean the socket itself is unusable, still fail it; everything else, a short send included, is loss, logged at most once a minute (ECONNREFUSED and EMSGSIZE at debug). Receives also tolerate ECONNRESET and EMSGSIZE, as tokio does. The ring's sockets now set IP(V6)_PMTUDISC_PROBE and IPV6_DONTFRAG like moq-sock's, so a forged ICMP fragmentation-needed cannot shrink a path below a GSO train. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EeyiEy5FWz3z44DYZVo7vU --- quest/m1/README.md | 1 - quest/m1/uring-local-addr.md | 4 - quest/m1/uring-mtu.md | 4 - quest/m1/uring-send-errors.md | 56 ------- quest/m2/relay-io-uring-package.md | 1 - rs/moq-uring/README.md | 5 +- rs/moq-uring/src/udp.rs | 237 +++++++++++++++++++++++++++-- 7 files changed, 225 insertions(+), 83 deletions(-) delete mode 100644 quest/m1/uring-send-errors.md diff --git a/quest/m1/README.md b/quest/m1/README.md index 01d60ffd8a8..94d5ff1ab92 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -82,7 +82,6 @@ tracks, so per-group stats stop costing cluster announces. - [Routing guide](/quest/m1/routing-guide.md) - concepts and practical outbound federation setup - [Controlled time](/quest/m1/time/README.md) - every crate and package reads time through moq-clock or @moq/clock, with regression tests for the changed contracts - [Own the QUIC stack](/quest/m1/quic/README.md) - quinn hard-forked in-tree as `moq-quic`, carrying BBR, reliable reset, hierarchical scheduling, peer limits, and endpoint sharding -- [A failed send never fails the io_uring socket](/quest/m1/uring-send-errors.md) - a send error costs one packet or destination, never every connection on the worker - [io_uring MTU matches tokio](/quest/m1/uring-mtu.md) - a 1200-byte floor and `quic.mtu_discovery` honored, so the ring stops black-holing smaller paths - [io_uring replies from the address it was reached on](/quest/m1/uring-local-addr.md) - packet info in and out, so multihomed wildcard binds work - [Rust request credit](/quest/m1/rs-request-credit.md) - a moq-net request fails at once without stream credit instead of waiting diff --git a/quest/m1/uring-local-addr.md b/quest/m1/uring-local-addr.md index 4131d54b892..b8947c01de0 100644 --- a/quest/m1/uring-local-addr.md +++ b/quest/m1/uring-local-addr.md @@ -42,7 +42,3 @@ through `moq_uring::udp::Transmit`, which callers construct by literal, so it gains a `src_ip: Option` field and `#[non_exhaustive]` with a constructor in the same change, with a `rs/moq-uring/MIGRATE.md` entry. Wire: none. - -## Related - -- [A failed send never fails the socket](/quest/m1/uring-send-errors.md) - same socket diff --git a/quest/m1/uring-mtu.md b/quest/m1/uring-mtu.md index 3c77129ee34..4f7259bf8af 100644 --- a/quest/m1/uring-mtu.md +++ b/quest/m1/uring-mtu.md @@ -44,7 +44,3 @@ Public API: additive, a `mtu_discovery: bool` field on the `moq_tokio::quic::Resolved::mtu_discovery`. Wire: none. Config: `quic.mtu_discovery` works under `--runtime-io-uring`; update `doc/bin/relay/` if it mentions the refusal. - -## Related - -- [A failed send never fails the socket](/quest/m1/uring-send-errors.md) - sets `PMTUDISC_PROBE` and `IPV6_DONTFRAG`, which `allow_mtud` relies on diff --git a/quest/m1/uring-send-errors.md b/quest/m1/uring-send-errors.md deleted file mode 100644 index 63da0a1b50c..00000000000 --- a/quest/m1/uring-send-errors.md +++ /dev/null @@ -1,56 +0,0 @@ -# [M] A failed send never fails the io_uring socket - -## Goal - -A send error on one io_uring worker's shared UDP socket costs at most that -packet or that destination, as on the tokio backend, so one peer can never -take down every connection on the worker. Only an error meaning the socket -itself is gone (EBADF and the like) still fails it. A test injects each -recoverable error class beside a healthy connection on the same socket and -proves the healthy one survives. - -## Plan - -Today `on_send` (`rs/moq-uring/src/udp.rs`) ignores ECONNREFUSED, routes -unreachable errors to their destination, and falls back from GSO on -EIO/EINVAL; every other error (EPERM, ENOMEM, EMSGSIZE, a short send) calls -`fail_tx`, which is sticky, so every later `poll_acquire` fails and each -connection's `flush_one` dies with it. The relay has one socket per worker -and keeps accepting connections that are already dead. EPERM is the -realistic trigger: a netfilter drop or a full conntrack table, which a -spoofed-source flood can fill, and the endpoint's stateless replies to -strangers share the socket. - -- Classify like tokio's `send_failed` (`rs/moq-tokio/src/quic/driver/runtime/mod.rs`): - per-packet errors are loss, logged at a bounded rate; unreachable errors - stay per destination; only an error that means the socket itself is gone - (EBADF and the like) fails it. Settle the exact split from the errno list, - not by porting tokio's line by line. -- Set `IP_PMTUDISC_PROBE` / `IPV6_PMTUDISC_PROBE` on the ring's sockets, as - `moq-sock/src/udp/unix.rs` does for tokio, so a forged ICMP - fragmentation-needed cannot shrink a peer's path MTU below a GSO train and - turn its next send into EMSGSIZE or a worker-wide GSO fallback. On IPv6 - also set `IPV6_DONTFRAG`, as moq-sock does: Linux's IPv6 output path can - still fragment under `IPV6_PMTUDISC_PROBE` alone, and MTU discovery needs - oversized probes dropped, not fragmented. moq-sock tolerates a missing - option by marking the socket as fragmenting; moq-uring is Linux-only, - where both exist, so a failure to set either fails socket construction. -- Receive errors: anything but ENOBUFS and ECANCELED fails the endpoint; - match tokio's tolerance (ConnectionReset, EMSGSIZE) in the same change. -- Test by injecting completion results into the socket's send path, since - the kernel rarely produces them on demand. -- The `rs/moq-uring/README.md` claim that GitHub runners skip the suite is - stale: `uring.yml` (release gate) and the nightly `rs uring` job run it on - `ubuntu-24.04-arm` with `MOQ_STRICT=1`. Fix it here. - -The worker-wide GSO fallback on EIO/EINVAL stays: `moq-sock` does the same, -and with `PMTUDISC_PROBE` set a peer can no longer trigger it. - -Decided 2026-10-22 from the io_uring audit: m1, since a peer can trigger it. - -Public API: none. Wire: none. - -## Related - -- [io_uring MTU parity](/quest/m1/uring-mtu.md) - same socket; PMTU probing lands there -- [io_uring local address](/quest/m1/uring-local-addr.md) - same socket's control messages diff --git a/quest/m2/relay-io-uring-package.md b/quest/m2/relay-io-uring-package.md index 7177a1201ce..7140ba781f3 100644 --- a/quest/m2/relay-io-uring-package.md +++ b/quest/m2/relay-io-uring-package.md @@ -42,7 +42,6 @@ Public API: none. Wire: none. ## Required -- [A failed send never fails the socket](/quest/m1/uring-send-errors.md) - one peer cannot kill a worker's connections - [io_uring MTU matches tokio](/quest/m1/uring-mtu.md) - `quic.mtu_discovery` honored and smaller paths reachable - [io_uring local address](/quest/m1/uring-local-addr.md) - multihomed wildcard binds reply from the right address - [io_uring handle lifecycle](/quest/m2/uring-lifecycle.md) - handles fail with their worker and close on last drop diff --git a/rs/moq-uring/README.md b/rs/moq-uring/README.md index 676249bc4b3..ef313719d76 100644 --- a/rs/moq-uring/README.md +++ b/rs/moq-uring/README.md @@ -106,8 +106,9 @@ steered two-worker reuseport group serving one port across threads, and `tests/integration/web.rs` is WebTransport interop against moq-tokio's: stream and datagram echo through the H3 framing, close codes through the capsule, and a full moq-lite session over -WebTransport. All of them skip (loudly) below the kernel floor, which -includes GitHub-hosted CI runners. +WebTransport. All of them skip (loudly) below the kernel floor. CI runs them +on `ubuntu-24.04-arm`, whose kernel clears it, with `MOQ_STRICT=1` refusing a +skip: in the `uring.yml` release gate and the nightly `rs uring` job. ## Benchmarks diff --git a/rs/moq-uring/src/udp.rs b/rs/moq-uring/src/udp.rs index 13100b57acc..b057aac1d55 100644 --- a/rs/moq-uring/src/udp.rs +++ b/rs/moq-uring/src/udp.rs @@ -422,6 +422,8 @@ pub(crate) struct SockShared { /// Starts as `config.gso`, and clears for good once the kernel rejects a /// train: the route or driver cannot segment. gso: Cell, + /// When a lost send was last logged, so a flood of them logs once per interval. + lost_logged: Cell>, bgid: u16, closed: Cell, rx: RefCell, @@ -505,6 +507,25 @@ impl SockShared { tx.error.get_or_insert(code); tx.waiters.wake(); } + + /// `op` is lost, which QUIC recovers like any other loss: log it, at most once an interval, + /// except the losses a peer causes as a matter of course. + fn lost(&self, op: &SendOp, err: io::Error) { + if matches!(err.raw_os_error(), Some(libc::ECONNREFUSED | libc::EMSGSIZE)) { + tracing::debug!(%err, to = %op.to, "send lost"); + return; + } + let now = moq_clock::now(); + if self + .lost_logged + .get() + .is_some_and(|last| now.saturating_duration_since(last) < LOST_LOG_INTERVAL) + { + return; + } + self.lost_logged.set(Some(now)); + tracing::warn!(%err, to = %op.to, len = op.expect, "send lost"); + } } impl Drop for SockShared { @@ -574,6 +595,21 @@ impl Socket { set_option(&io, libc::IPPROTO_IPV6, libc::IPV6_RECVTCLASS)?; } set_option(&io, libc::IPPROTO_IP, libc::IP_RECVTOS)?; + // Send at the interface MTU and never fragment, as moq-sock does, so a forged ICMP + // fragmentation-needed cannot shrink a path below a GSO train and turn its sends into + // EMSGSIZE or a worker-wide GSO fallback. The v4 option covers v4-mapped peers on a v6 + // socket too. IPv6 also needs DONTFRAG, since its output path can still fragment under + // PMTUDISC_PROBE alone. + set_value(&io, libc::IPPROTO_IP, libc::IP_MTU_DISCOVER, libc::IP_PMTUDISC_PROBE)?; + if io.local_addr()?.is_ipv6() { + set_value( + &io, + libc::IPPROTO_IPV6, + libc::IPV6_MTU_DISCOVER, + libc::IPV6_PMTUDISC_PROBE, + )?; + set_option(&io, libc::IPPROTO_IPV6, libc::IPV6_DONTFRAG)?; + } // The ring's entry count is fixed at registration, so it is sized for // the ceiling; the buffers behind it are allocated as the pool grows. @@ -638,6 +674,7 @@ impl Socket { shard, metrics: shared.metrics.clone(), gso: Cell::new(config.gso), + lost_logged: Cell::new(None), config, bgid, closed: Cell::new(false), @@ -956,6 +993,25 @@ impl TxBuf { } } +impl TxBuf { + /// Stage this lease as a send to `to` that never reaches the kernel, for a test to complete + /// with whatever result it injects. + #[cfg(test)] + fn fake_send(mut self, to: SocketAddr) -> SendOp { + self.armed = true; + self.sock.stage_tx(self.id); + let expect = self.data.len(); + self.sock.tx.borrow_mut().bufs[self.id as usize].data = std::mem::take(&mut self.data); + SendOp { + sock: self.sock.clone(), + id: self.id, + expect, + to, + train: None, + } + } +} + impl std::ops::Deref for TxBuf { type Target = Vec; @@ -1244,6 +1300,9 @@ pub(crate) fn on_recv( } // Socket teardown; nothing to surface. libc::ECANCELED => return, + // What tokio tolerates too: ICMP surfacing on the socket (ECONNRESET), and a + // datagram too large for the buffer (EMSGSIZE). Each costs at most one receive. + libc::ECONNRESET | libc::EMSGSIZE => {} _ => { sock.fail_rx(code); return; @@ -1376,11 +1435,6 @@ fn on_recv_oneshot(one: OneshotRecv, cqe: Cqe) -> Result<(u16, Option), pub(crate) fn on_send(op: SendOp, cqe: Cqe) { if cqe.result < 0 { let code = -cqe.result; - if code == libc::ECONNREFUSED { - // ICMP unreachable noise; QUIC treats it as loss. - tracing::debug!("send completed with ECONNREFUSED"); - return; - } // Linux has no way to ask whether a route or driver can segment; it // only fails the train with EIO or EINVAL. Dropping the train would // cost the connection a full RTO, so send it again unsegmented. Other @@ -1394,19 +1448,49 @@ pub(crate) fn on_send(op: SendOp, cqe: Cqe) { } return; } - if moq_sock::udp::is_unreachable_err(&io::Error::from_raw_os_error(code)) { - op.sock.unreachable(op.to, code); - return; - } - if code != libc::ECANCELED { - op.sock.fail_tx(code); + match SendFailure::of(code) { + SendFailure::Cancelled => {} + SendFailure::Unreachable => op.sock.unreachable(op.to, code), + SendFailure::Lost => op.sock.lost(&op, io::Error::from_raw_os_error(code)), + SendFailure::Socket => op.sock.fail_tx(code), } } else if cqe.result as usize != op.expect { - tracing::warn!(sent = cqe.result, expected = op.expect, "short UDP send"); - op.sock.fail_tx(libc::EIO); + let short = format!("short send: {} of {} bytes", cqe.result, op.expect); + op.sock.lost(&op, io::Error::other(short)); } } +/// What a failed send costs, decided by its errno. +#[derive(Debug, PartialEq, Eq)] +enum SendFailure { + /// The socket is closing. + Cancelled, + /// No route to the destination: its connection decides whether to give up on the peer. + Unreachable, + /// This packet, which UDP always allows. A peer can provoke most of these, through a + /// netfilter drop (EPERM), a full conntrack table, memory pressure, or ICMP (ECONNREFUSED, + /// EMSGSIZE from an MTU probe), so none of them may cost the other connections sharing the + /// socket. + Lost, + /// The socket itself is unusable, so every later send would fail the same way. + Socket, +} + +impl SendFailure { + fn of(code: i32) -> Self { + match code { + libc::ECANCELED => Self::Cancelled, + code if moq_sock::udp::is_unreachable_err(&io::Error::from_raw_os_error(code)) => Self::Unreachable, + // Not a socket, closed under us, or a buffer the kernel cannot read. + libc::EBADF | libc::ENOTSOCK | libc::EFAULT => Self::Socket, + _ => Self::Lost, + } + } +} + +/// How often a socket logs a lost send. +const LOST_LOG_INTERVAL: std::time::Duration = std::time::Duration::from_secs(60); + /// Stage a rejected GSO train again, one `sendmsg` per segment, from the /// buffer `op` still holds. Runs before `op` drops, so the slot stays leased. fn resend_unsegmented(op: &SendOp, base: NonNull, one: &SendOne) -> io::Result<()> { @@ -1506,14 +1590,18 @@ fn read_int(data: &[u8]) -> Option { /// Turn a boolean socket option on. fn set_option(io: &UdpSocket, level: libc::c_int, name: libc::c_int) -> io::Result<()> { - let on: libc::c_int = 1; + set_value(io, level, name, 1) +} + +/// Set an integer socket option. +fn set_value(io: &UdpSocket, level: libc::c_int, name: libc::c_int, value: libc::c_int) -> io::Result<()> { // SAFETY: valid fd, valid option buffer. let ret = unsafe { libc::setsockopt( io.as_raw_fd(), level, name, - (&raw const on).cast(), + (&raw const value).cast(), std::mem::size_of::() as libc::socklen_t, ) }; @@ -1696,6 +1784,125 @@ mod tests { assert!(!grow_rx(&mut rx, &config), "grew past the ceiling"); } + /// Every errno is either loss, a destination, the socket, or teardown, and only the errors + /// meaning the socket itself is gone fail it. + #[test] + fn send_errors_fail_the_socket_only_when_it_is_gone() { + for code in [libc::EBADF, libc::ENOTSOCK, libc::EFAULT] { + assert_eq!(SendFailure::of(code), SendFailure::Socket, "{code}"); + } + for code in [libc::ENETUNREACH, libc::EHOSTUNREACH, libc::ENETDOWN] { + assert_eq!(SendFailure::of(code), SendFailure::Unreachable, "{code}"); + } + for code in [ + libc::EPERM, + libc::EACCES, + libc::ENOMEM, + libc::ENOBUFS, + libc::EMSGSIZE, + libc::ECONNREFUSED, + libc::EAGAIN, + libc::EINVAL, + libc::EIO, + ] { + assert_eq!(SendFailure::of(code), SendFailure::Lost, "{code}"); + } + assert_eq!(SendFailure::of(libc::ECANCELED), SendFailure::Cancelled); + } + + /// A send that completes with a recoverable error, or short, costs that packet: the socket + /// it shares with every other connection on the worker keeps sending. An error that means + /// the socket is gone still fails it. + #[test] + fn a_failed_send_costs_only_its_packet() { + let mut worker = match crate::Worker::new(crate::Config::default()) { + Ok(worker) => worker, + Err(Error::Unsupported(reason)) if std::env::var_os("MOQ_STRICT").is_none() => { + eprintln!("skipping io_uring socket test: {reason}"); + return; + } + Err(err) => panic!("worker setup failed: {err}"), + }; + let handle = worker.handle(); + let peer = std::net::UdpSocket::bind("127.0.0.1:0").expect("peer"); + peer.set_read_timeout(Some(std::time::Duration::from_secs(10))) + .expect("timeout"); + let to = peer.local_addr().expect("peer addr"); + let io = UdpSocket::bind("127.0.0.1:0").expect("bind"); + let sock = handle.udp(io, Config::default()).expect("socket"); + + let lost = [ + libc::EPERM, + libc::EACCES, + libc::ENOMEM, + libc::ENOBUFS, + libc::EMSGSIZE, + libc::EINVAL, + ]; + let err = worker + .block_on(async { + for code in lost { + let mut tx = sock.acquire().await.expect("a lost send keeps the socket"); + tx.extend_from_slice(b"lost"); + on_send( + tx.fake_send(to), + Cqe { + user_data: 0, + result: -code, + flags: 0, + }, + ); + } + let mut tx = sock.acquire().await.expect("a short send keeps the socket"); + tx.extend_from_slice(b"short"); + on_send( + tx.fake_send(to), + Cqe { + user_data: 0, + result: 2, + flags: 0, + }, + ); + + // Still sending: a real datagram reaches the peer. + let mut tx = sock.acquire().await.expect("send buffer"); + tx.extend_from_slice(b"alive"); + tx.send(Transmit { + to, + segment: 5, + ecn: None, + }) + .expect("staged"); + // Let the worker submit it and reap its completion. + for _ in 0..1000 { + if sock.shared.tx.borrow().bufs.iter().all(|buf| buf.in_flight == 0) { + break; + } + crate::Timer::after(&handle, std::time::Duration::from_millis(1)) + .wait() + .await; + } + + let mut tx = sock.acquire().await.expect("send buffer"); + tx.extend_from_slice(b"gone"); + on_send( + tx.fake_send(to), + Cqe { + user_data: 0, + result: -libc::EBADF, + flags: 0, + }, + ); + sock.acquire().await.expect_err("a socket-gone error fails the socket") + }) + .expect("worker"); + assert_eq!(err.raw_os_error(), Some(libc::EBADF), "{err}"); + + let mut buf = [0u8; 16]; + let (len, _) = peer.recv_from(&mut buf).expect("the healthy send arrived"); + assert_eq!(&buf[..len], b"alive"); + } + /// With nothing routing unreachable reports, a send that finds no route /// fails later sends like any other error instead of queueing a report /// nobody will collect. Linux refuses a v4-mapped destination on an From f046619dce4518bd1678a572fac482dc0ce66cf7 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 22 Oct 2026 16:29:05 -0700 Subject: [PATCH 3/5] docs(uring): a lost send no longer fails the next acquire TxBuf::send still promised every failed send surfaced on the next pool acquire. Only an unusable socket, or an unrouted unreachable send, does now. Co-Authored-By: Claude Opus 5.5 --- rs/moq-uring/src/udp.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/rs/moq-uring/src/udp.rs b/rs/moq-uring/src/udp.rs index b057aac1d55..a119d98ed0e 100644 --- a/rs/moq-uring/src/udp.rs +++ b/rs/moq-uring/src/udp.rs @@ -485,10 +485,10 @@ impl SockShared { rx.waiters.wake(); } - /// A send to `to` found no route. Unlike other send failures this says - /// nothing about the socket, so with a consumer only the connections - /// dialing `to` hear it. Without one there is no destination to route it - /// to, so it fails sends like any other error. + /// A send to `to` found no route, which says nothing about the socket, so + /// with a consumer only the connections dialing `to` hear it. Without one + /// there is no destination to route it to, so it fails the socket: a raw + /// socket has no other way to report it. fn unreachable(&self, to: SocketAddr, code: i32) { let mut rx = self.rx.borrow_mut(); let Some(reports) = rx.unreachable.as_mut() else { @@ -906,8 +906,10 @@ pub struct TxBuf { impl TxBuf { /// Send the buffer on the owning socket as datagrams of `segment` bytes /// (the last may be short), marked with `ecn`. Fire-and-forget: - /// the buffer returns to the pool when the kernel completes, and a - /// failed send surfaces on the next pool acquire. + /// the buffer returns to the pool when the kernel completes. A send the + /// kernel fails or cuts short is lost, as UDP allows, and only logged. + /// The next pool acquire fails only once the socket itself is unusable + /// or a send finds no route to its destination. /// /// This only stages an SQE, so the datagram reaches the kernel when the /// worker next enters the ring. Dropping the worker makes a bounded attempt @@ -1904,9 +1906,9 @@ mod tests { } /// With nothing routing unreachable reports, a send that finds no route - /// fails later sends like any other error instead of queueing a report - /// nobody will collect. Linux refuses a v4-mapped destination on an - /// IPv6-only socket with `ENETUNREACH`. + /// fails later sends instead of queueing a report nobody will collect. + /// Linux refuses a v4-mapped destination on an IPv6-only socket with + /// `ENETUNREACH`. #[test] fn a_raw_socket_sees_an_unreachable_send_fail() { use nix::sys::socket::{AddressFamily, SockFlag, SockType, SockaddrIn6, bind, setsockopt, socket, sockopt}; From d63be9ba069e734a136c6fcb6bd62b5b3f091135 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 22 Oct 2026 17:02:44 -0700 Subject: [PATCH 4/5] fix(uring): match tokio's MTU and honor quic.mtu_discovery The ring pinned its initial and minimum MTU at 1350 bytes and advertised a 1350-byte max_udp_payload_size, so a path carrying fewer bytes (an IPv6 path at its 1280-byte minimum, a tunnel) black-holed the handshake. Drop the overrides so the ring starts at moq-quic's 1200-byte floor like tokio, add `quic::Transport::mtu_discovery` (off by default), allow discovery on the endpoint now that every socket refuses to fragment, and size each GSO train from the connection's current MTU. The relay maps `quic.mtu_discovery` instead of refusing it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EeyiEy5FWz3z44DYZVo7vU --- doc/bin/relay/config.md | 4 +- quest/m1/README.md | 1 - quest/m1/uring-mtu.md | 46 --- quest/m2/perf/uring-profile.md | 4 +- quest/m2/relay-io-uring-package.md | 1 - rs/moq-relay/src/uring.rs | 17 +- rs/moq-uring/src/quic/driver/connection.rs | 21 +- rs/moq-uring/src/quic/driver/endpoint.rs | 9 +- rs/moq-uring/src/quic/driver/mod.rs | 25 +- rs/moq-uring/src/quic/mod.rs | 9 +- rs/moq-uring/tests/integration/main.rs | 1 + rs/moq-uring/tests/integration/mtu.rs | 374 +++++++++++++++++++++ 12 files changed, 422 insertions(+), 90 deletions(-) delete mode 100644 quest/m1/uring-mtu.md create mode 100644 rs/moq-uring/tests/integration/mtu.rs diff --git a/doc/bin/relay/config.md b/doc/bin/relay/config.md index b76ef9e601c..dc2d89b7212 100644 --- a/doc/bin/relay/config.md +++ b/doc/bin/relay/config.md @@ -174,8 +174,8 @@ first cores, so two relays on one host, or one limited to fewer CPUs than the host has, would crowd onto them. Turn it on for a host the relay has to itself. `io_uring` additionally needs Linux 6.12+ and the `io-uring` cargo feature; it -shares the same reloadable TLS identity, serves every configured version -like the shared runtime, and refuses `mtu_discovery`. A setting the build or host cannot deliver refuses to +shares the same reloadable TLS identity and serves every configured version +like the shared runtime. A setting the build or host cannot deliver refuses to start rather than being ignored. If io\_uring workers fail to start naming `RLIMIT_MEMLOCK`, raise it (`LimitMEMLOCK=` under systemd). diff --git a/quest/m1/README.md b/quest/m1/README.md index 94d5ff1ab92..9b71fa964f6 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -82,7 +82,6 @@ tracks, so per-group stats stop costing cluster announces. - [Routing guide](/quest/m1/routing-guide.md) - concepts and practical outbound federation setup - [Controlled time](/quest/m1/time/README.md) - every crate and package reads time through moq-clock or @moq/clock, with regression tests for the changed contracts - [Own the QUIC stack](/quest/m1/quic/README.md) - quinn hard-forked in-tree as `moq-quic`, carrying BBR, reliable reset, hierarchical scheduling, peer limits, and endpoint sharding -- [io_uring MTU matches tokio](/quest/m1/uring-mtu.md) - a 1200-byte floor and `quic.mtu_discovery` honored, so the ring stops black-holing smaller paths - [io_uring replies from the address it was reached on](/quest/m1/uring-local-addr.md) - packet info in and out, so multihomed wildcard binds work - [Rust request credit](/quest/m1/rs-request-credit.md) - a moq-net request fails at once without stream credit instead of waiting - [Generated C bindings](/quest/m1/c/README.md) - C generated from moq-ffi ships as `moq-c` 0.8.0 and replaces the hand-written libmoq diff --git a/quest/m1/uring-mtu.md b/quest/m1/uring-mtu.md deleted file mode 100644 index 4f7259bf8af..00000000000 --- a/quest/m1/uring-mtu.md +++ /dev/null @@ -1,46 +0,0 @@ -# [M] io_uring MTU matches tokio - -## Goal - -An io_uring relay connects over any path that carries 1200-byte QUIC -payloads, exactly as the tokio backend does, and `quic.mtu_discovery` is -honored instead of refused: off by default, discovering larger MTUs when on. - -## Plan - -`rs/moq-uring/src/quic/driver/mod.rs` pins the initial and minimum MTU to -`SEGMENT` (1350), disables discovery, and advertises a 1350 -`max_udp_payload_size`; `rs/moq-relay/src/uring.rs` refuses -`quic.mtu_discovery`. Tokio uses moq-quic's 1200 floor and 1472 -advertised, and maps the resolved `quic.mtu_discovery` (default false) -onto `mtu_discovery_config` (`rs/moq-tokio/src/quic/backend.rs`). A path below ~1378 bytes (IPv4) or ~1398 -(IPv6) black-holes on the ring with no fallback. - -The pin dates from the quiche-era driver and was never re-justified. Its GSO -rationale no longer holds: `flush_one` already sends with moq-quic's own -`transmit.segment_size`, and moq-quic sizes GSO batches itself (#6279). Only -`segments = capacity / SEGMENT` in `connection.rs` assumes the fixed size; -derive it from the current MTU instead. - -Drop the overrides so the ring uses the same `TransportConfig` defaults as -tokio, add the resolved setting to `moq_uring::quic::Transport` so -discovery stays off unless configured, and lift the relay's refusal. Also -pass `allow_mtud = true` to `moq_quic::Endpoint::new` -(`rs/moq-uring/src/quic/driver/endpoint.rs`), which hardcodes `false` -today and would veto discovery for every connection whatever the setting; -it is sound only once the sockets refuse to fragment (`PMTUDISC_PROBE` plus -`IPV6_DONTFRAG`, from the send-errors quest), so land that first or set -them here. Reproduce first: a test path that -passes 1200-byte payloads but drops 1350 fails today and connects after. -Then cover discovery staying off by default, a path MTU change -mid-connection, and a larger MTU being discovered when enabled, with GSO -trains still batching. - -Decided 2026-10-22 from the io_uring audit: m1, since it black-holes real -paths. - -Public API: additive, a `mtu_discovery: bool` field on the -`#[non_exhaustive]` `moq_uring::quic::Transport`, named after -`moq_tokio::quic::Resolved::mtu_discovery`. Wire: none. Config: -`quic.mtu_discovery` works under `--runtime-io-uring`; update -`doc/bin/relay/` if it mentions the refusal. diff --git a/quest/m2/perf/uring-profile.md b/quest/m2/perf/uring-profile.md index 221ca382e1f..63af9989598 100644 --- a/quest/m2/perf/uring-profile.md +++ b/quest/m2/perf/uring-profile.md @@ -28,8 +28,8 @@ profile, and plan a quest only for one that shows up: - atomic RMWs in worker metrics (remote wake counters genuinely have several writers); - receive rearm churn that `IORING_RECVSEND_POLL_FIRST` would cut; -- GSO batching on ordinary and jumbo paths after - [MTU parity](/quest/m1/uring-mtu.md). +- GSO batching on ordinary and jumbo paths, now that discovery can raise + the MTU. Decided 2026-10-22 from the io_uring audit. diff --git a/quest/m2/relay-io-uring-package.md b/quest/m2/relay-io-uring-package.md index 7140ba781f3..d7fa2d514db 100644 --- a/quest/m2/relay-io-uring-package.md +++ b/quest/m2/relay-io-uring-package.md @@ -42,7 +42,6 @@ Public API: none. Wire: none. ## Required -- [io_uring MTU matches tokio](/quest/m1/uring-mtu.md) - `quic.mtu_discovery` honored and smaller paths reachable - [io_uring local address](/quest/m1/uring-local-addr.md) - multihomed wildcard binds reply from the right address - [io_uring handle lifecycle](/quest/m2/uring-lifecycle.md) - handles fail with their worker and close on last drop - [Ring drain GOAWAY](/quest/m2/uring-ring-drain.md) - closes are delivered on the ring for moq-transport too diff --git a/rs/moq-relay/src/uring.rs b/rs/moq-relay/src/uring.rs index 371bea3f427..8a251ff2bd4 100644 --- a/rs/moq-relay/src/uring.rs +++ b/rs/moq-relay/src/uring.rs @@ -414,12 +414,6 @@ impl std::fmt::Debug for Workers { /// One qlog sink is built for the whole group and cloned into every worker, so /// the traces share a single writer thread however many workers there are. fn transport(quic: &moq_tokio::quic::Resolved) -> anyhow::Result { - // The datagram path fixes both payload ceilings at SEGMENT and hands - // `conn.send` slices of exactly that, so there is no larger size to find. - anyhow::ensure!( - !quic.mtu_discovery, - "io_uring workers send a fixed-size UDP payload, so quic.mtu_discovery has nothing to discover" - ); // The tokio path reports this through `moq_tokio::Error::QlogUnsupported`, // which nothing builds here: this listener is the io_uring stack. #[cfg(not(feature = "qlog"))] @@ -449,6 +443,7 @@ fn transport(quic: &moq_tokio::quic::Resolved) -> anyhow::Result return Poll::Pending, }; - let segments = (tx.capacity() / SEGMENT).min(TRAIN_SEGMENTS); - if segments == 0 { - return Poll::Ready(Err(Error::Io(format!( - "transmit buffer of {} bytes holds no {SEGMENT} byte segment", - tx.capacity() - )))); - } - let (transmit, closing) = { let mut conn = self.shared.conn.borrow_mut(); + // moq-quic packs every full datagram at the current MTU, which + // discovery can raise, so a train sized for any smaller one would + // outgrow the buffer. + let mtu = usize::from(conn.current_mtu()); + let segments = (tx.capacity() / mtu).min(TRAIN_SEGMENTS); + if segments == 0 { + return Poll::Ready(Err(Error::Io(format!( + "transmit buffer of {} bytes holds no {mtu} byte datagram", + tx.capacity() + )))); + } // moq-quic encrypts the train straight into the socket's buffer. // Nothing to send, or paced; the buffer returns to the pool on drop. let Some(transmit) = conn.poll_transmit(self.shared.owner.now(), segments, &mut tx) else { diff --git a/rs/moq-uring/src/quic/driver/endpoint.rs b/rs/moq-uring/src/quic/driver/endpoint.rs index e4f7af62def..46144b87cc1 100644 --- a/rs/moq-uring/src/quic/driver/endpoint.rs +++ b/rs/moq-uring/src/quic/driver/endpoint.rs @@ -102,12 +102,13 @@ impl Endpoint { None => None, }; let accepting = server.is_some().then(|| Accepting { queue: VecDeque::new() }); - // MTU discovery is off (the GSO pool sends fixed SEGMENT datagrams), - // so the endpoint has no reason to allow it either. + // Every `udp::Socket` refuses to fragment, so a probe too large for the + // path is lost rather than delivered in pieces, and discovery can trust + // what arrives. Each connection's transport still decides whether to probe. let endpoint = moq_quic::Endpoint::new( - super::endpoint_config(socket.shard(), config.reset_secret.as_ref())?, + super::endpoint_config(socket.shard(), config.reset_secret.as_ref()), server, - false, + true, ); let inner = Rc::new(Inner { diff --git a/rs/moq-uring/src/quic/driver/mod.rs b/rs/moq-uring/src/quic/driver/mod.rs index b4d516fca0a..603edf4020d 100644 --- a/rs/moq-uring/src/quic/driver/mod.rs +++ b/rs/moq-uring/src/quic/driver/mod.rs @@ -29,7 +29,7 @@ use rustls::pki_types::{CertificateDer, PrivateKeyDer}; #[cfg(feature = "qlog")] use super::qlog; -use super::{Congestion, Error, Identity, SEGMENT, Transport, client, server}; +use super::{Congestion, Error, Identity, Transport, client, server}; use crate::udp; /// Per-stream flow control credit, which returns as bytes are read, so it only paces a stream. @@ -41,8 +41,8 @@ const CONNECTION_WINDOW: u32 = 128 * 1024 * 1024; const _: () = assert!(CONNECTION_WINDOW as u64 >= moq_net::transport::MIN_RECEIVE_WINDOW); /// Unacknowledged outgoing data to buffer, whatever the peer allows. const SEND_WINDOW: u32 = 16 * 1024 * 1024; -/// How many datagrams to buffer in each direction. -const DATAGRAM_WINDOW: usize = 64 * SEGMENT; +/// Datagram bytes to buffer in each direction, about 64 full-size datagrams. +const DATAGRAM_WINDOW: usize = 96 * 1024; fn ecn_to_quic(ecn: udp::Ecn) -> moq_quic::EcnCodepoint { match ecn { @@ -96,12 +96,11 @@ fn provider() -> Arc { .clone() } -/// The endpoint-wide configuration: how connection ids are minted, the reset -/// key, and the largest datagram we tell peers we can receive. +/// The endpoint-wide configuration: how connection ids are minted and the reset key. pub(crate) fn endpoint_config( shard: Option, reset_secret: Option<&[u8; 32]>, -) -> Result, Error> { +) -> Arc { let mut config = moq_quic::EndpointConfig::default(); // The random ids below validate a predecessor's too, so the reset reaches them. if let Some(secret) = reset_secret { @@ -119,10 +118,7 @@ pub(crate) fn endpoint_config( } Box::new(cids) })); - config - .max_udp_payload_size(SEGMENT as u16) - .map_err(|err| Error::Quic(err.to_string()))?; - Ok(Arc::new(config)) + Arc::new(config) } /// Dial as `config` says. @@ -282,11 +278,10 @@ fn transport_config(config: &Transport) -> Result Arc::new(moq_quic::congestion::CubicConfig::default()) as Arc, diff --git a/rs/moq-uring/src/quic/mod.rs b/rs/moq-uring/src/quic/mod.rs index 4974ad785fa..a3df1115b69 100644 --- a/rs/moq-uring/src/quic/mod.rs +++ b/rs/moq-uring/src/quic/mod.rs @@ -35,10 +35,6 @@ pub use endpoint::Endpoint; /// The flow-control limits a live connection can change; see [`Connection::set_limits`]. pub use moq_quic::{Limits, LimitsError}; -/// The QUIC payload size every full datagram in a GSO train uses, and the -/// stride GRO coalesces with. -pub(crate) const SEGMENT: usize = 1350; - /// A TLS certificate chain and the private key that signs for it, as PEM. /// One value, so neither half can be configured alone. /// @@ -138,6 +134,10 @@ pub struct Transport { /// connection, or `None` (the default) to send none and let the idle /// timeout decide. pub keep_alive: Option, + /// Probe for a path MTU above the 1200-byte floor every QUIC path carries, + /// off by default. A probe the path drops costs only itself, and a path + /// that later shrinks falls back to the floor. + pub mtu_discovery: bool, /// Where to write qlog traces, or `None` (the default) to write none. /// /// moq-quic takes one sink per transport config, so this writes one file @@ -160,6 +160,7 @@ impl Default for Transport { send_window: None, congestion: Congestion::default(), keep_alive: None, + mtu_discovery: false, #[cfg(feature = "qlog")] qlog: None, } diff --git a/rs/moq-uring/tests/integration/main.rs b/rs/moq-uring/tests/integration/main.rs index 83833a76650..a9d0fcc6995 100644 --- a/rs/moq-uring/tests/integration/main.rs +++ b/rs/moq-uring/tests/integration/main.rs @@ -14,6 +14,7 @@ mod echo; mod ecn; mod endpoint; mod identity; +mod mtu; mod qlog; mod receive_credit; mod session; diff --git a/rs/moq-uring/tests/integration/mtu.rs b/rs/moq-uring/tests/integration/mtu.rs new file mode 100644 index 00000000000..b03de41da57 --- /dev/null +++ b/rs/moq-uring/tests/integration/mtu.rs @@ -0,0 +1,374 @@ +//! Path MTU through the io_uring driver: a path that carries only the QUIC +//! floor still connects, discovery stays off unless asked, and when on it +//! finds a larger MTU, keeps batching GSO trains at it, and falls back when +//! the path shrinks. +//! +//! The path is a userspace hop that drops whatever exceeds its MTU without a +//! word, the way a tunnel behind a firewall that eats ICMP does. It crosses +//! real sockets, so these run on the wall clock. +//! +//! Unsupported local kernels skip loudly; MOQ_STRICT makes CI refuse them. + +#![cfg(all(target_os = "linux", feature = "quic"))] + +use crate::support; + +use std::net::{SocketAddr, UdpSocket}; +use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering}; +use std::sync::{Arc, Mutex}; +use std::task::Poll; +use std::time::Duration; + +use moq_uring::{Config, Error, Worker, quic, udp}; +use web_transport_trait::poll::{RecvStream as _, SendStream as _, Session as _}; + +const ALPN: &str = "moq-uring-mtu"; +/// The UDP payload every QUIC path must carry, and moq-quic's floor. +const FLOOR: usize = 1200; +/// The UDP payload an IPv6 path must carry: the 1280-byte minimum link MTU +/// less the IPv6 and UDP headers. Above the floor, below a 1350-byte pin. +const IPV6_MIN: usize = 1232; +/// The UDP payload of an Ethernet path over IPv4. +const ETHERNET: usize = 1472; +/// Enough data for full GSO trains. +const PAYLOAD: usize = 1 << 20; + +fn worker() -> Option { + match Worker::new(Config::default()) { + Ok(worker) => Some(worker), + Err(Error::Unsupported(reason)) if std::env::var_os("MOQ_STRICT").is_none() => { + eprintln!("skipping io_uring MTU test: {reason}"); + None + } + Err(err) => panic!("worker setup failed: {err}"), + } +} + +/// What one direction of a [`Path`] forwarded. +#[derive(Default)] +struct Seen { + /// The largest datagram, in bytes. + largest: AtomicUsize, + /// Datagrams larger than the floor. + large: AtomicU64, +} + +impl Seen { + fn forwarded(&self, len: usize) { + self.largest.fetch_max(len, Ordering::Relaxed); + if len > FLOOR { + self.large.fetch_add(1, Ordering::Relaxed); + } + } +} + +/// A hop between one client and `server` that silently drops every datagram +/// larger than its MTU, which can change mid-connection. +struct Path { + addr: SocketAddr, + mtu: Arc, + /// Toward the server, then back toward the client. + seen: Arc<[Seen; 2]>, + stop: Arc, + threads: Vec>, +} + +impl Path { + fn new(server: SocketAddr, mtu: usize) -> Self { + let front = UdpSocket::bind("127.0.0.1:0").expect("bind the client side"); + let back = UdpSocket::bind("127.0.0.1:0").expect("bind the server side"); + back.connect(server).expect("connect to the server"); + // Short, so a thread notices `stop` promptly. + for sock in [&front, &back] { + sock.set_read_timeout(Some(Duration::from_millis(10))) + .expect("read timeout"); + } + let addr = front.local_addr().expect("path address"); + let front = Arc::new(front); + let back = Arc::new(back); + let client: Arc>> = Arc::default(); + let mtu = Arc::new(AtomicUsize::new(mtu)); + let seen: Arc<[Seen; 2]> = Arc::default(); + let stop = Arc::new(AtomicBool::new(false)); + + let up = { + let (front, back, client, mtu, seen, stop) = ( + front.clone(), + back.clone(), + client.clone(), + mtu.clone(), + seen.clone(), + stop.clone(), + ); + std::thread::spawn(move || { + let mut buf = vec![0u8; 64 * 1024]; + while !stop.load(Ordering::Relaxed) { + let Ok((len, from)) = front.recv_from(&mut buf) else { + continue; + }; + *client.lock().unwrap() = Some(from); + if len <= mtu.load(Ordering::Relaxed) && back.send(&buf[..len]).is_ok() { + seen[0].forwarded(len); + } + } + }) + }; + let down = { + let (mtu, seen, stop) = (mtu.clone(), seen.clone(), stop.clone()); + std::thread::spawn(move || { + let mut buf = vec![0u8; 64 * 1024]; + while !stop.load(Ordering::Relaxed) { + let Ok(len) = back.recv(&mut buf) else { + continue; + }; + let Some(to) = *client.lock().unwrap() else { + continue; + }; + if len <= mtu.load(Ordering::Relaxed) && front.send_to(&buf[..len], to).is_ok() { + seen[1].forwarded(len); + } + } + }) + }; + + Self { + addr, + mtu, + seen, + stop, + threads: vec![up, down], + } + } + + fn set_mtu(&self, mtu: usize) { + self.mtu.store(mtu, Ordering::Relaxed); + } + + /// The largest datagram forwarded either way. + fn largest(&self) -> usize { + self.seen + .iter() + .map(|seen| seen.largest.load(Ordering::Relaxed)) + .max() + .unwrap_or_default() + } + + /// Datagrams larger than the floor forwarded toward the server. + fn large_up(&self) -> u64 { + self.seen[0].large.load(Ordering::Relaxed) + } +} + +impl Drop for Path { + fn drop(&mut self) { + self.stop.store(true, Ordering::Relaxed); + for thread in self.threads.drain(..) { + let _ = thread.join(); + } + } +} + +/// Await `future`, failing loudly rather than hanging if it never resolves. +async fn within(handle: &moq_uring::Handle, what: &str, future: impl Future) -> T { + let mut deadline = moq_uring::Timer::after(handle, Duration::from_secs(10)); + let mut future = std::pin::pin!(future); + kio::wait(|waiter| { + let mut cx = waiter.context(); + if let Poll::Ready(value) = future.as_mut().poll(&mut cx) { + return Poll::Ready(Some(value)); + } + deadline.poll(waiter).map(|()| None) + }) + .await + .unwrap_or_else(|| panic!("timed out waiting for {what}")) +} + +/// A server endpoint and a dial-only client, both running `transport`, with +/// the client's dial going through a path of `mtu`. +fn endpoints( + handle: &moq_uring::Handle, + transport: &quic::Transport, + mtu: usize, +) -> (quic::Endpoint, quic::Endpoint, quic::client::Config, Path) { + let certs = support::certs().expect("certificates"); + let socket = |handle: &moq_uring::Handle| { + handle + .udp(UdpSocket::bind("127.0.0.1:0").expect("bind"), udp::Config::default()) + .expect("socket") + }; + let mut server_config = quic::server::Config::new( + quic::Identity::open(&certs.cert, &certs.key) + .expect("identity") + .server(&[ALPN], quic::server::ClientAuth::None) + .expect("tls"), + ); + server_config.transport = transport.clone(); + let server = quic::Endpoint::new( + socket(handle), + quic::endpoint::Config::default().with_server(server_config), + ) + .expect("server endpoint"); + let client = quic::Endpoint::new(socket(handle), quic::endpoint::Config::default()).expect("client endpoint"); + let path = Path::new(server.local_addr(), mtu); + let mut dial = quic::client::Config::new(path.addr, "localhost"); + dial.alpn = vec![ALPN.to_string()]; + dial.verify = false; + dial.transport = transport.clone(); + (server, client, dial, path) +} + +/// Dial through the path and accept the far end. +async fn connect( + handle: &moq_uring::Handle, + server: &quic::Endpoint, + client: &quic::Endpoint, + dial: &quic::client::Config, +) -> (quic::Connection, quic::Connection) { + let dialed = within(handle, "the handshake", client.connect(dial)) + .await + .expect("dial"); + let accepted = within(handle, "the accept", server.accept()).await.expect("accept"); + (dialed, accepted) +} + +/// Send `len` bytes on a fresh stream from `from` and read them all at `to`. +async fn transfer(handle: &moq_uring::Handle, from: &mut quic::Connection, to: &mut quic::Connection, len: usize) { + let mut send = std::future::poll_fn(|cx| from.poll_open_uni(cx)) + .await + .expect("open_uni"); + handle.spawn(async move { + let payload = vec![7u8; len]; + let mut buf = &payload[..]; + while !buf.is_empty() { + match std::future::poll_fn(|cx| send.poll_write(cx, buf)).await { + Ok(n) => buf = &buf[n..], + Err(_) => return, + } + } + let _ = send.finish(); + let _ = std::future::poll_fn(|cx| send.poll_closed(cx)).await; + }); + + let read = within(handle, "the transfer", async { + let mut recv = std::future::poll_fn(|cx| to.poll_accept_uni(cx)) + .await + .expect("accept_uni"); + let mut buf = vec![0u8; 64 * 1024]; + let mut read = 0; + while let Some(n) = std::future::poll_fn(|cx| recv.poll_read(cx, &mut buf)) + .await + .expect("read") + { + read += n; + } + read + }) + .await; + assert_eq!(read, len, "the whole stream arrived"); +} + +/// A path that carries the floor but not a byte more than IPv6 promises +/// connects and carries data. +#[test] +fn a_path_at_the_ipv6_minimum_connects() { + let Some(mut worker) = worker() else { return }; + let handle = worker.handle(); + let (server, client, dial, path) = endpoints(&handle, &quic::Transport::default(), IPV6_MIN); + + worker + .block_on(async move { + let (mut dialed, mut accepted) = connect(&handle, &server, &client, &dial).await; + transfer(&handle, &mut dialed, &mut accepted, PAYLOAD).await; + transfer(&handle, &mut accepted, &mut dialed, PAYLOAD).await; + }) + .expect("worker"); + assert!(path.largest() <= IPV6_MIN); +} + +/// Without discovery, nothing either way exceeds the floor, however much the +/// path would carry. +#[test] +fn discovery_stays_off_by_default() { + let Some(mut worker) = worker() else { return }; + let handle = worker.handle(); + let (server, client, dial, path) = endpoints(&handle, &quic::Transport::default(), ETHERNET); + + worker + .block_on(async move { + let (mut dialed, mut accepted) = connect(&handle, &server, &client, &dial).await; + transfer(&handle, &mut dialed, &mut accepted, PAYLOAD).await; + transfer(&handle, &mut accepted, &mut dialed, PAYLOAD).await; + }) + .expect("worker"); + assert_eq!(path.largest(), FLOOR, "every full datagram sits at the floor"); +} + +/// Transfer until discovery has raised the MTU past the floor, so a train +/// staged after it packs the larger datagrams. +async fn discover(handle: &moq_uring::Handle, from: &mut quic::Connection, to: &mut quic::Connection, path: &Path) { + for _ in 0..50 { + transfer(handle, from, to, PAYLOAD / 16).await; + if path.large_up() > 0 { + return; + } + } + panic!("discovery never sent past the floor"); +} + +/// With discovery on, a path that carries more than the floor gets it, and +/// trains keep batching at the larger size. +#[test] +fn discovery_finds_a_larger_mtu() { + let Some(mut worker) = worker() else { return }; + let handle = worker.handle(); + let mut transport = quic::Transport::default(); + transport.mtu_discovery = true; + let (server, client, dial, path) = endpoints(&handle, &transport, ETHERNET); + + let metrics = handle.metrics(); + let (path, (datagrams, sends)) = worker + .block_on(async move { + let (mut dialed, mut accepted) = connect(&handle, &server, &client, &dial).await; + discover(&handle, &mut dialed, &mut accepted, &path).await; + + let before = (metrics.snapshot(), path.large_up()); + transfer(&handle, &mut dialed, &mut accepted, PAYLOAD).await; + let after = metrics.snapshot(); + // Most of the transfer rode above the floor. + let large = path.large_up() - before.1; + assert!(large as usize > PAYLOAD / ETHERNET / 2, "{large} large datagrams"); + ( + path, + ( + after.tx_datagrams - before.0.tx_datagrams, + after.tx_sends - before.0.tx_sends, + ), + ) + }) + .expect("worker"); + assert!(path.largest() > FLOOR, "discovered {}", path.largest()); + assert!(path.largest() <= ETHERNET, "discovered {}", path.largest()); + assert!(datagrams > 2 * sends, "{datagrams} datagrams in {sends} sends"); +} + +/// A path that shrinks after discovery black-holes the larger datagrams, and +/// the connection falls back to the floor instead of stalling. +#[test] +fn a_shrinking_path_falls_back_to_the_floor() { + let Some(mut worker) = worker() else { return }; + let handle = worker.handle(); + let mut transport = quic::Transport::default(); + transport.mtu_discovery = true; + let (server, client, dial, path) = endpoints(&handle, &transport, ETHERNET); + + worker + .block_on(async move { + let (mut dialed, mut accepted) = connect(&handle, &server, &client, &dial).await; + discover(&handle, &mut dialed, &mut accepted, &path).await; + + path.set_mtu(IPV6_MIN); + transfer(&handle, &mut dialed, &mut accepted, PAYLOAD).await; + transfer(&handle, &mut accepted, &mut dialed, PAYLOAD).await; + }) + .expect("worker"); +} From 0be76ee3c54698a9ae13ecb41c2c03e93310afa9 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 23 Oct 2026 12:43:13 -0700 Subject: [PATCH 5/5] test(relay): drop an allow the lint no longer needs Co-Authored-By: Claude Opus 5.5 --- rs/moq-relay/src/uring.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/rs/moq-relay/src/uring.rs b/rs/moq-relay/src/uring.rs index e113d610e84..c31971b8944 100644 --- a/rs/moq-relay/src/uring.rs +++ b/rs/moq-relay/src/uring.rs @@ -903,7 +903,6 @@ mod tests { /// `quic.mtu_discovery` reaches the workers as it does the tokio backends: off unless set. #[test] - #[allow(clippy::field_reassign_with_default)] fn mtu_discovery_is_applied() { let mut quic = moq_tokio::quic::Config::default(); assert!(!transport(&quic.resolve()).expect("default").mtu_discovery);