Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion quest/m0/ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ The historical samples locate candidates; they are not controlled benchmarks.

- [Pin Quest's gate](/quest/m0/ci/quest-gate-pin.md) - make shared command admission available
- [Share local check capacity](/quest/m0/ci/local-gate.md) - gate expensive phases and bound internal fanout
- [Windows restart drill](/quest/m0/ci/platform-windows-drill.md) - the relay restart drill passes on Windows in the merge queue
- [Require platform gates](/quest/m0/ci/platform-queue.md) - activate the consolidated platform checks in the main and release rulesets after the workflow lands
- [mbx on R2](/quest/m0/ci/mbx-r2.md) - Rust builds on every OS read an R2 cache that only `main` writes, escaping the 10 GB Actions cache
- [Nix cache](/quest/m0/ci/nix-cache.md) - `nix.moq.dev` on R2 replaces Cachix for CI and releases
Expand Down
5 changes: 2 additions & 3 deletions quest/m0/ci/nightly-green.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
## Goal

Every Nightly workload that failed on 2026-10-16 (run 38897397428, commit
b4eab0db1) passes on the next scheduled run, except the ones other quests own:
the Linux release builds ([Release builds link again](/quest/m0/release-link.md))
and the Windows relay drill ([Windows restart drill](/quest/m0/ci/platform-windows-drill.md)).
b4eab0db1) passes on the next scheduled run, except the Linux release builds,
which [Release builds link again](/quest/m0/release-link.md) owns.

## Plan

Expand Down
4 changes: 0 additions & 4 deletions quest/m0/ci/platform-queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ the implementation PR.
- Nightly and releases share the five-job macOS cap. Measure overlap with
queue runs before reserving capacity or reducing the queue build limit.

## Required

- [Windows restart drill](/quest/m0/ci/platform-windows-drill.md) - a required Platform gate would block every merge while it fails

## Related

- [mbx on R2](/quest/m0/ci/mbx-r2.md) - gives platform jobs a Rust cache
19 changes: 0 additions & 19 deletions quest/m0/ci/platform-windows-drill.md

This file was deleted.

78 changes: 76 additions & 2 deletions rs/moq-shaper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ async fn run(

loop {
let (size, from) = tokio::select! {
res = listen.recv_from(&mut buf) => res.context("receive from a client")?,
res = recv(&listen, &mut buf) => res.context("receive from a client")?,
Some(res) = tasks.join_next() => {
res.context("flow task panicked")??;
continue;
Expand Down Expand Up @@ -817,7 +817,7 @@ async fn reply(
) -> anyhow::Result<()> {
let mut buf = vec![0u8; u16::MAX as usize];
loop {
let (size, from) = socket.recv_from(&mut buf).await.context("receive from the target")?;
let (size, from) = recv(&socket, &mut buf).await.context("receive from the target")?;
// Anything else reaching this ephemeral port is not part of the path.
if from != *target.lock().expect("target poisoned") || is_cut(&cuts) {
continue;
Expand All @@ -828,6 +828,19 @@ async fn reply(
}
}

/// Receive the next datagram, skipping the port unreachable an earlier send
/// drew. Windows reports one as `ConnectionReset` even on an unconnected
/// socket, but a peer that went away (a killed relay, a closed client) is the
/// path losing datagrams, not the shaper failing.
async fn recv(socket: &UdpSocket, buf: &mut [u8]) -> std::io::Result<(usize, SocketAddr)> {
loop {
match socket.recv_from(buf).await {
Err(err) if err.kind() == std::io::ErrorKind::ConnectionReset => continue,
res => return res,
}
}
}

/// Send each treated datagram at its departure time, after its batch if the
/// link has one.
async fn deliver(
Expand Down Expand Up @@ -1388,6 +1401,67 @@ mod tests {
assert!(shaper.retarget(ipv6).is_err(), "retargeted where no flow can reach");
}

#[tokio::test(start_paused = true)]
async fn a_closed_target_loses_datagrams_until_a_retarget() {
let dead = UdpSocket::bind(LOCALHOST).await.unwrap();
let next = UdpSocket::bind(LOCALHOST).await.unwrap();
let shaper = Shaper::bind(Config {
bind: LOCALHOST,
target: dead.local_addr().unwrap(),
seed: 1,
up: Profile::default(),
down: Profile::default(),
})
.await
.unwrap();
let client = UdpSocket::bind(LOCALHOST).await.unwrap();
client.connect(shaper.addr()).await.unwrap();
let mut buf = [0u8; 8];

client.send(b"before").await.unwrap();
dead.recv_from(&mut buf).await.unwrap();

// The flow sends to the closed port, drawing an error on its next receive.
drop(dead);
client.send(b"lost").await.unwrap();
while shaper.stats().up.packets < 2 {
tokio::time::sleep(Duration::from_millis(1)).await;
}

shaper.retarget(next.local_addr().unwrap()).unwrap();
client.send(b"after").await.unwrap();
let (size, flow) = tokio::time::timeout(Duration::from_secs(1), next.recv_from(&mut buf))
.await
.expect("the retarget never forwarded")
.unwrap();
assert_eq!(&buf[..size], b"after");
next.send_to(b"reply", flow).await.unwrap();
let size = tokio::time::timeout(Duration::from_secs(1), client.recv(&mut buf))
.await
.expect("the reply never arrived")
.unwrap();
assert_eq!(&buf[..size], b"reply");
shaper.verify().unwrap();
}

#[tokio::test(start_paused = true)]
async fn a_closed_client_leaves_the_others_forwarding() {
let (shaper, client) = setup(1, Profile::default(), Profile::default()).await;

// The echo returns to the closed port, drawing an error on the listening socket.
let gone = UdpSocket::bind(LOCALHOST).await.unwrap();
gone.connect(shaper.addr()).await.unwrap();
gone.send(b"gone").await.unwrap();
drop(gone);
while shaper.stats().down.packets < 1 {
tokio::time::sleep(Duration::from_millis(1)).await;
}

let got = round_trip(&client, 10).await;
assert_eq!(got, (0..10).collect::<Vec<_>>());
shaper.verify().unwrap();
}

#[tokio::test(start_paused = true)]
async fn an_undelayed_datagram_waits_for_no_timer() {
let (_shaper, client) = setup(1, Profile::default(), Profile::default()).await;
Expand Down
23 changes: 17 additions & 6 deletions rs/moq-shaper/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ use tokio::sync::mpsc;

type Datagram = (SocketAddr, Vec<u8>);

/// What a receive returns next: a datagram, or the error an earlier send drew.
type Arrival = io::Result<Datagram>;

/// Every bound socket by port, which is the whole address on this network.
static PORTS: LazyLock<Mutex<HashMap<u16, mpsc::UnboundedSender<Datagram>>>> = LazyLock::new(Default::default);
static PORTS: LazyLock<Mutex<HashMap<u16, mpsc::UnboundedSender<Arrival>>>> = LazyLock::new(Default::default);
static NEXT_PORT: AtomicU16 = AtomicU16::new(1);

pub struct UdpSocket {
addr: SocketAddr,
peer: OnceLock<SocketAddr>,
queue: tokio::sync::Mutex<mpsc::UnboundedReceiver<Datagram>>,
queue: tokio::sync::Mutex<mpsc::UnboundedReceiver<Arrival>>,
}

impl UdpSocket {
Expand Down Expand Up @@ -54,17 +57,25 @@ impl UdpSocket {
self.peer.set(peer).map_err(|_| io::ErrorKind::AlreadyExists.into())
}

/// Like UDP, a datagram to a port nobody bound is lost without an error.
/// A datagram to a port nobody bound is lost, and the sender's next receive
/// fails with `ConnectionReset`: Windows reports the port unreachable that
/// way even on an unconnected socket, where Linux and macOS stay silent.
pub async fn send_to(&self, buf: &[u8], dest: SocketAddr) -> io::Result<usize> {
if let Some(port) = PORTS.lock().unwrap().get(&dest.port()) {
let _ = port.send((self.addr, buf.to_vec()));
let ports = PORTS.lock().unwrap();
match ports.get(&dest.port()) {
Some(port) => {
let _ = port.send(Ok((self.addr, buf.to_vec())));
}
None => {
let _ = ports[&self.addr.port()].send(Err(io::ErrorKind::ConnectionReset.into()));
}
}
Ok(buf.len())
}

pub async fn recv_from(&self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
// The port's sender lives until this socket drops, so the queue never ends.
let (from, datagram) = self.queue.lock().await.recv().await.expect("bound port");
let (from, datagram) = self.queue.lock().await.recv().await.expect("bound port")?;
let size = datagram.len().min(buf.len());
buf[..size].copy_from_slice(&datagram[..size]);
Ok((size, from))
Expand Down