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
11 changes: 11 additions & 0 deletions quest/m0/test-flakes-3/webrtc-live-source.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# [S] The WHIP and WHEP round trips play under load

## Goal

The `moq-webrtc` tests that wait on a packet the source pushed once before its viewer connected pass however loaded the host is: `a_whep_viewer_ends_with_its_broadcast`, `a_whep_viewer_joining_after_the_catalog_ends_plays_the_rest`, `a_whep_viewer_stays_on_its_instance_until_the_route_dies`, `a_whip_push_stays_on_its_instance_until_the_route_dies`, and `whip_and_whep_round_trip_opus`.

## Plan

Found while fixing [a_reoffer_from_the_same_address_plays](https://github.com/moq-dev/moq/pull/9241), which failed for the same cause. Run sixteen copies of one of these at once inside `systemd-run --user --scope -p CPUQuota=100%` and every copy times out at 10 s waiting for its first packet. None has flaked in a real `just check` yet, only a_reoffer did.

The cause: `Bridge::push` cuts a group per packet, so a packet's group has an (empty) successor at once and goes stale 100 ms later (`egress::MAX_DELAY`). A session that connects past that budget under load reads nothing, and the test's source never pushes again. `a_reoffer_from_the_same_address_plays` now keeps a live source sending (`played_live`) until its viewer plays. Do the same here, sharing the helper rather than copying it: the sources that also need an exact payload (`OLD_PACKET` after a take-over) push it as their live packet instead of a one-shot.
12 changes: 0 additions & 12 deletions quest/m0/test-flakes-3/webrtc-reoffer-load.md

This file was deleted.

15 changes: 15 additions & 0 deletions quest/m3/webrtc/reoffer-dtls-flight.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# [S] A re-offered session's first DTLS flight reaches it

## Goal

A viewer that re-offers from the address its abandoned session still holds completes DTLS without waiting out a DTLS retransmit (about 0.9 s), because its first flight reaches the new session.

## Plan

Found while fixing [a_reoffer_from_the_same_address_plays](https://github.com/moq-dev/moq/pull/9241), which takes ~1 s of its 1.1 s in this wait on an idle host. In `server/mux.rs`, a datagram that is not STUN goes to the address's holder alone (`Datagram::Other`). The re-offering peer starts DTLS the moment its ICE completes, and its ClientHello can reach the mux 40 us before the new session's ICE connects and `Route::confirm` moves the address, so the old session receives and drops it. Only dimpl's first retransmit recovers.

Measured with a debug print in `Registry::route` and `Route::confirm`: ClientHello routed to the old holder with `claims.contains_key(src)`, then `confirm` 43 us later.

Options: route `Datagram::Other` to the claimant as well as the holder, as `Datagram::Answer` already does (check that str0m drops DTLS from a pair ICE has not verified, so a forged source gains nothing), or hold the claimant's own first flight until it confirms. Prefer the first unless the second is simpler once the code is read. Test with a re-offer whose first flight is sent before the confirm, asserting the new session plays well under one retransmit interval on a paused or manual clock if the sockets allow it, otherwise by a lower bound on the flight count.

Public API: none. Wire: none.
42 changes: 24 additions & 18 deletions rs/moq-webrtc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,41 +408,47 @@ mod tests {
http.abort();
}

/// The next payload `viewer` receives while `bridge` keeps sending from `at`, as a live
/// source does. Each packet's group ends whole where the packet does, so a paused source's
/// last one ages out before a session that connects past its delay budget reads it, which
/// a loaded host does to the first packet as readily as the second.
async fn played_live(
bridge: &mut dyn Bridge,
at: &mut u64,
viewer: &mut tokio::sync::mpsc::UnboundedReceiver<Vec<u8>>,
) -> Vec<u8> {
let read = received(viewer);
tokio::pin!(read);
loop {
push(bridge, *at, NEW_PACKET);
*at += 20_000;
tokio::select! {
played = &mut read => return played.expect("the viewer was closed"),
_ = kio::clock::sleep(Duration::from_millis(20)) => {}
}
}
}

/// A viewer re-offering from the address its abandoned session still holds plays on its
/// new session: the new session's ICE confirms the path, so the address moves to it.
#[tokio::test]
async fn a_reoffer_from_the_same_address_plays() {
let origin = moq_tokio::origin::spawn();
let (_route, mut bridge, _catalog) = publish_opus(&origin, moq_net::Instance::random());
push(&mut *bridge, 20_000, OPUS_PACKET);
let mut at = 20_000;

let (url, http, mut sessions) = serve_whep(&origin).await;
let udp = std::sync::Arc::new(tokio::net::UdpSocket::bind("127.0.0.1:0").await.unwrap());
let (old, mut viewer) = raw_view_on(url.clone(), udp.clone()).await;
let _old_session = sessions.recv().await.unwrap();
assert_eq!(received(&mut viewer).await.as_deref(), Some(OPUS_PACKET));
assert_eq!(played_live(&mut *bridge, &mut at, &mut viewer).await, NEW_PACKET);

// The peer drops its connection without a word, then offers again from the same address.
old.abort();
let _ = old.await;
let (_new, mut viewer) = raw_view_on(url, udp).await;
let _new_session = sessions.recv().await.unwrap();
// The source keeps sending, as a live one does: each packet's group ends whole where the
// packet does, so a paused source's last one ages out before a session arriving past its
// delay budget reads it.
let read = received(&mut viewer);
tokio::pin!(read);
let mut at = 40_000;
let played = loop {
push(&mut *bridge, at, NEW_PACKET);
at += 20_000;
tokio::select! {
played = &mut read => break played,
_ = kio::clock::sleep(Duration::from_millis(20)) => {}
}
};
let played = played.expect("the new session never played");
assert!([OPUS_PACKET, NEW_PACKET].contains(&played.as_slice()), "{played:?}");
assert_eq!(played_live(&mut *bridge, &mut at, &mut viewer).await, NEW_PACKET);
http.abort();
}

Expand Down