From 9165f5be2d704b3bc2195d14c0f32c128cb247f7 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 22 Oct 2026 18:15:44 -0700 Subject: [PATCH 1/2] fix(net): a reconnecting publisher wins over its lingering session on release A publisher that drops without a clean close and reconnects announces under a new first hop: its own random id, or this relay's per-connection stamp. Until the old session idles out, route_order's rendezvous hash picks between the dead and live session by coin flip, so new subscribers land on the dead broadcast and get its cached tail, then nothing. Hash only routes a cluster peer forwarded; a route that entered here falls through to the newest announcement. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/origin.rs | 38 +++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index b3b139ed31e..35ffc90b2e0 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -648,13 +648,21 @@ fn fnv_key(name: &str, origins: impl IntoIterator) -> u64 { /// of the prefix and chain so every node converges on the same winner, and finally /// the newest announcement, so a reconnect under an otherwise identical route wins /// the moment it lands instead of after the transport retires the old session. +/// +/// Only a route a cluster peer forwarded is hashed. One that entered here is ranked +/// by no other node, and a restarted publisher announces under a new first hop (its +/// own random id, or this relay's stamp), so a hash would keep its dead session +/// winning half the time until the transport times out. fn route_order(prefix: &Path, entry: &RouteEntry) -> (bool, Cost, bool, usize, u64, Reverse) { ( entry.is_anonymous(), entry.cost, !entry.local, entry.hops.len(), - fnv_key(prefix.as_str(), entry.hops.iter().copied()), + match entry.peer { + true => fnv_key(prefix.as_str(), entry.hops.iter().copied()), + false => 0, + }, Reverse(entry.id), ) } @@ -7353,6 +7361,34 @@ mod tests { } } + /// A publisher that reconnects before its old session times out announces under a + /// new first hop: a random id when it names itself, or this relay's stamp when it + /// does not. The new session wins whichever chain hashes lower. + #[tokio::test(start_paused = true)] + async fn a_reconnect_under_a_new_hop_wins_over_the_old_session() { + for (old, new) in [ + (&[10][..], &[11][..]), + (&[11], &[10]), + (&[10, 0], &[11, 0]), + (&[11, 0], &[10, 0]), + ] { + let producer = origin(1).produce(); + let mut announced = producer.consume().announced(); + tokio::time::sleep(Duration::from_millis(1)).await; + + let _old = producer.dynamic("room", Route::default().with_hops(hops(old))).unwrap(); + assert_eq!(announced.assert_next_active("room").hops, hops(old)); + + let _new = producer.dynamic("room", Route::default().with_hops(hops(new))).unwrap(); + let update = tokio::time::timeout(DEFAULT_UPDATE_HOLD * 2, announced.next()) + .await + .unwrap_or_else(|_| panic!("{new:?} never took over from {old:?}")) + .unwrap(); + assert_eq!(update.kind, AnnounceKind::Updated); + assert_eq!(update.route.hops, hops(new)); + } + } + #[tokio::test] async fn withdrawn_route_no_longer_covers_requests() { let producer = origin(1).produce(); From 2bf1e42c60a713eda4a7d8d94a3bb694816acb01 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 22 Oct 2026 18:40:07 -0700 Subject: [PATCH 2/2] docs(net): Route::cost hashes only peer-forwarded routes Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/origin.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index 35ffc90b2e0..671c3c9dc9f 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -519,8 +519,8 @@ pub struct Route { /// What pulling content via this route costs, accumulated per link: lower wins /// among routes of the same anonymity, with ties broken by a broadcast published - /// on this origin, then hop length, then a deterministic hash, and finally the - /// most recently announced route. See [`Cost`]. + /// on this origin, then hop length, then a deterministic hash of a route a cluster + /// peer forwarded, and finally the most recently announced route. See [`Cost`]. pub cost: Cost, /// The announcing session's declared or assigned identity.