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
6 changes: 6 additions & 0 deletions doc/bin/relay/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ same way so the cluster converges instead of flapping. Both wire protocols
carry it: natively on moq-lite, and via the [cluster extension](/draft/moq-cluster)
on moq-transport 17+.

moq-transport drafts 14 and 15 cannot ask for every broadcast, since an empty
namespace prefix is illegal before draft 16. On such a link to a peer without
the MoQ Solicit extension, such as moxygen, the relay does not ask for the
whole namespace and learns only what the peer announces unasked. moxygen
announces nothing unasked on draft 14, so that link discovers no broadcasts.

When a moq-lite-04 or later peer withdraws its last advertisement for a broadcast, a relay
drops every other route to it that passed through that peer, since each was
relayed from what the peer just withdrew, rather than falling back to them one
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/goaway-requests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ test("announcing and subscribing after GOAWAY still open streams, on the adapter
close() {},
};

const subscriber = new Subscriber({ session, goaway });
// A soliciting peer, so draft-14 still asks it for the empty namespace.
const subscriber = new Subscriber({ session, goaway, solicit: true });
const track = subscriber.consume(Path.from("room")).track("video").subscribe();
await track.closed;
expect(opened).toBe(true);
Expand Down
9 changes: 8 additions & 1 deletion js/net/src/ietf/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,14 @@ export class Connection implements Established {
});
this.#solicit = solicit;
this.#cluster = cluster;
this.#subscriber = new Subscriber({ session: this.#session, quic, cluster, hidden, goaway: this.#goaway });
this.#subscriber = new Subscriber({
session: this.#session,
quic,
cluster,
hidden,
solicit,
goaway: this.#goaway,
});
registerWire(this, { consume: (path) => this.#subscriber.consume(path), goaway: this.#goaway });

void this.#run(early);
Expand Down
76 changes: 76 additions & 0 deletions js/net/src/ietf/subscriber.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,82 @@ test("every peer is asked", async () => {
expect(await nextStream(pair.client)).toBeDefined();
});

/**
* Draft-16 is the first that allows a zero-field track namespace. Asking a foreign peer
* (one that declared no MoQ Solicit) for one earlier is a protocol violation, so an
* unscoped subscriber sends nothing and still takes an unsolicited announcement.
*/
test.each([
["draft-14", Version.DRAFT_14, ALPN.DRAFT_14],
["draft-15", Version.DRAFT_15, ALPN.DRAFT_15],
] as const)("%s does not ask a foreign peer for the empty namespace", async (_name, version, alpn) => {
const pair = createMockTransportPair(alpn);
const session = new NativeSession(pair.server, version, true);
const subscriber = new Subscriber({ session });
const announced = subscriber.announced();

expect(await nextStream(pair.client)).toBeUndefined();

const stream = await Stream.open(pair.server, { version });
void subscriber.runPublishNamespace(
new PublishNamespace({ requestId: 0n, trackNamespace: Path.from("surprise") }),
stream,
);
expect(await announced.next()).toMatchObject({ prefix: Path.from("surprise"), kind: "start" });
announced.close();
});

/** With no request stream to end it, the unasked reader ends with the session, from either side. */
test.each([
["local", "server"],
["remote", "client"],
] as const)("an unasked draft-14 reader ends on a %s close", async (_name, side) => {
const pair = createMockTransportPair(ALPN.DRAFT_14);
const session = new NativeSession(pair.server, Version.DRAFT_14, true);
const subscriber = new Subscriber({ session, quic: pair.server });
const announced = subscriber.announced();

pair[side].close();

expect(await announced.next()).toBeUndefined();
});

/** A peer that declared MoQ Solicit is ours: it only tells when asked, so it still is. */
test.each([
["draft-14", Version.DRAFT_14, ALPN.DRAFT_14],
["draft-15", Version.DRAFT_15, ALPN.DRAFT_15],
] as const)("%s still asks a soliciting peer for the empty namespace", async (_name, version, alpn) => {
const pair = createMockTransportPair(alpn);
const session = new NativeSession(pair.server, version, true);
const subscriber = new Subscriber({ session, solicit: true });

subscriber.announced();

expect(await nextStream(pair.client)).toBeDefined();
});

/** A named prefix is still legal on the drafts that reject the empty one. */
test("draft-14 still asks for a named prefix", async () => {
const pair = createMockTransportPair(ALPN.DRAFT_14);
const session = new NativeSession(pair.server, Version.DRAFT_14, true);
const subscriber = new Subscriber({ session });

subscriber.announced(Path.Pattern.subtree(Path.from("cam")));

expect(await nextStream(pair.client)).toBeDefined();
});

/** The empty prefix is the "every namespace" request from draft-16 on. */
test("draft-16 still asks for the empty namespace", async () => {
const pair = createMockTransportPair(ALPN.DRAFT_16);
const session = new NativeSession(pair.server, Version.DRAFT_16, true);
const subscriber = new Subscriber({ session });

subscriber.announced();

expect(await nextStream(pair.client)).toBeDefined();
});

/**
* The other half of discovery: a peer that tells us unasked. Asking must not make us deaf
* to a PUBLISH_NAMESPACE that arrives on its own stream instead.
Expand Down
26 changes: 25 additions & 1 deletion js/net/src/ietf/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ export class Subscriber {
// Whether the peer understands the HIDDEN parameter (MoQ Hidden).
#hidden: boolean;

// What the peer's SETUP declared about being solicited (MoQ Solicit), `undefined`
// when it declared nothing.
#solicit?: boolean;

// Settles when the peer sends GOAWAY, repricing this session's routes to the drain cost.
#goaway?: GetPromise<Drain>;

Expand All @@ -174,6 +178,7 @@ export class Subscriber {
quic,
cluster,
hidden = false,
solicit,
goaway,
}: {
/** The session abstraction for bidi streams and request IDs. */
Expand All @@ -184,13 +189,16 @@ export class Subscriber {
cluster?: Cluster.Hops;
/** Whether the peer understands the HIDDEN parameter (MoQ Hidden). */
hidden?: boolean;
/** What the peer's SETUP declared about being solicited (MoQ Solicit). */
solicit?: boolean;
/** Settles when the peer sends GOAWAY. */
goaway?: GetPromise<Drain>;
}) {
this.#session = session;
this.#quic = quic;
this.#cluster = cluster;
this.#hidden = hidden;
this.#solicit = solicit;
this.#goaway = goaway;
// A draining peer usually stops publishing namespaces, so reprice from the signal
// itself. Waiting for another message would leave the route primary until close.
Expand Down Expand Up @@ -242,7 +250,9 @@ export class Subscriber {
*
* The peer is asked with SUBSCRIBE_NAMESPACE regardless of what it declared, and an
* unsolicited PUBLISH_NAMESPACE lands here too, so a peer that only tells and one
* that only answers are both discovered.
* that only answers are both discovered. A draft-14 or draft-15 peer that declared no
* MoQ Solicit is not asked for the empty prefix, so an unscoped subscriber only hears
* what that peer tells.
*
* Hidden routes (a `.`-prefixed segment below the scope's head) are left out unless
* `options.hidden` opts in. The opt-in rides the SUBSCRIBE_NAMESPACE when the peer
Expand Down Expand Up @@ -352,6 +362,20 @@ export class Subscriber {
async #runAnnounced(announced: announce.Producer, prefix: Path.Valid, hidden: boolean) {
const version = this.#session.version;

// A zero-field track namespace was a protocol violation until draft-16 allowed
// it. A peer that never declared MoQ Solicit is not ours: it may enforce that, and
// it tells us unasked anyway, so send nothing and stay registered for its
// unsolicited PUBLISH_NAMESPACE. Returning would drop this consumer before one
// could land. A peer that declared Solicit only tells when asked, so it still is.
const legacy = version === Version.DRAFT_14 || version === Version.DRAFT_15;
if (legacy && prefix.length === 0 && this.#solicit === undefined) {
// No request stream ends this wait, so the session's end has to.
const ends: PromiseLike<unknown>[] = [announced.closed];
if (this.#quic) ends.push(this.#quic.closed.catch(() => undefined));
await Promise.race(ends);
return;
Comment on lines +371 to +376

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] End skipped announcement readers when the session closes

For a draft-14/15 peer with no Solicit declaration, this wait has no connection-lifetime signal. No request stream exists to wake it on disconnect; Subscriber.close() only sets #localClose, and Connection.#close() only closes the transport/adapter. Consequently, after conn.abort() or a remote disconnect, a direct conn.announced() reader's pending next() and closed remain unsettled, and the producer stays registered until the caller explicitly closes it. Callers using stream termination for cleanup/reconnection can hang. forwardAnnounced closes its own reader on conn.closed, but that only protects the consume wiring. Race this wait against session/transport closure, or close these producers during all connection teardown paths, and add a local/remote-close regression test.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f066a4f: the skipped-request wait now races announced.closed against the transport's closed, so the reader ends on a local or remote close. Regression tests cover both sides and fail without the fix.

(Written by Claude Opus 5.5)

}

// Suffixes live on this stream, so a repeat is recognized as an update to the
// advertisement rather than a second one, which would leak the count.
const live = new Set<Path.Valid>();
Expand Down
1 change: 0 additions & 1 deletion quest/m0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ a published `@moq/watch` break.
- [Held group wakes](/quest/m0/held-group-wakes.md) - a group held across a route switch is woken when its successor's first timestamp or abort makes it stale, not at the next unrelated append
- [Draft-22 LOCATION_FILTER](/quest/m0/ietf-location-filter-22.md) - moqt-22 LOCATION_FILTER carries its type instead of a Length in Rust and JS, so a draft-22 peer reads our Next Object correctly
- [moq-transport parameters per draft](/quest/m0/ietf-params-per-draft.md) - every control message accepts exactly the parameters its draft allows, so moqx's draft-16 SUBSCRIBE_NAMESPACE with FORWARD stops failing
- [No empty d14 prefix](/quest/m0/ietf-d14-root-prefix.md) - draft-14 never sends SUBSCRIBE_NAMESPACE with an empty prefix, and the docs say to scope a d14 link to moxygen
- [End of Track Location](/quest/m0/ietf-end-of-track-location.md) - a relay forwards END_OF_TRACK at its upstream's Location, on the last group's stream, instead of re-sending it at the next group's object 0
- [End of Group status](/quest/m0/ietf-end-of-group-status.md) - an End of Group status on a stream whose header already marks the group's end is accepted, so imquic's last object per group arrives
- [Subgroup at object 0](/quest/m0/ietf-first-object-zero.md) - a draft-18 subgroup with FIRST_OBJECT clear that starts at object 0 is read whole
Expand Down
39 changes: 0 additions & 39 deletions quest/m0/ietf-d14-root-prefix.md

This file was deleted.

103 changes: 103 additions & 0 deletions rs/moq-net/src/ietf/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,109 @@ mod tests {
assert_eq!(occurrences(&log, b"rootns"), 0, "asked the peer for our local root");
}

/// The bytes of one legacy SUBSCRIBE_NAMESPACE, as the session writes them.
async fn subscribe_namespace_legacy(version: Version, namespace: &str) -> Vec<u8> {
let log = crate::lite::test_transport::Log::default();
let mut writer = Writer::new(crate::lite::test_transport::SinkSend::new(log.clone()), version);
let msg = ietf::SubscribeNamespaceLegacy {
request_id: RequestId(0),
namespace: crate::Path::new(namespace),
subscribe_options: ietf::SubscribeOptions::Namespace,
hidden: false,
};
writer.varint(ietf::SubscribeNamespaceLegacy::ID).await.unwrap();
writer.encode(&msg).await.unwrap();
log.writes.lock().unwrap().clone()
}

/// How many times a session with this scope writes SUBSCRIBE_NAMESPACE for it.
///
/// `prefix: None` is an unscoped origin, whose only interest head is empty. `solicit`
/// is what the peer's SETUP declared (MoQ Solicit).
async fn asked_namespace(version: Version, prefix: Option<&str>, solicit: Option<bool>) -> usize {
let origin = crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce();
let subscribe = match prefix {
Some(name) => {
let scope: crate::Patterns = [crate::Pattern::subtree(name).unwrap()].into_iter().collect();
origin.scope("rootns", &scope).expect("scope the origin")
}
None => origin,
};

let gate = kio::Producer::new(true);
let mut session = crate::lite::test_transport::SinkSession::gated_bi(gate.consume());
let log = session.log.clone();
let setup = Stream::open(&mut session, version)
.await
.expect("open the control stream");

let (driver, _goaway, _) = start(Config {
runtime: crate::time::Clock::sim(),
session,
setup: Some(setup),
request_id_max: None,
limits: Default::default(),
client: true,
publish: None,
subscribe: Some(subscribe),
peer_hop: None,
cost: None,
version,
path: None,
authority: None,
peer_setup_stream: None,
peer_declared: Some(peer::Peer {
solicit,
..Default::default()
}),
early_unis: Vec::new(),
})
.expect("start the session");
let driver = moq_net_sim::spawn(driver);

let needle = subscribe_namespace_legacy(version, prefix.unwrap_or("")).await;
for _ in 0..ANNOUNCE_TURNS {
if occurrences(&log, &needle) > 0 {
break;
}
moq_net_sim::sleep(std::time::Duration::from_millis(1)).await;
}

assert!(!driver.is_finished(), "{version:?} ended the session");
assert!(log.closes().is_empty(), "{version:?} closed: {:?}", log.closes());
occurrences(&log, &needle)
}

/// Draft-14 and draft-15 reject a zero-field track namespace, so a foreign peer (one
/// that declared no MoQ Solicit) is not asked for it, and a real prefix still goes
/// out. A peer that declared Solicit is ours: it only tells when asked, so it still
/// gets the empty prefix. Draft-16 made the empty prefix legal, so it stays.
#[moq_net_sim::test]
async fn an_empty_namespace_is_not_asked_of_a_foreign_peer_before_draft_16() {
for version in [Version::Draft14, Version::Draft15] {
assert_eq!(
asked_namespace(version, None, None).await,
0,
"{version:?} asked a foreign peer for every namespace"
);
assert_eq!(
asked_namespace(version, Some("cam"), None).await,
1,
"{version:?} skipped a real prefix"
);
assert_eq!(
asked_namespace(version, None, Some(true)).await,
1,
"{version:?} did not ask a soliciting peer for every namespace"
);
}
assert_eq!(
asked_namespace(Version::Draft16, None, None).await,
1,
"draft-16 dropped the empty prefix"
);
}

/// How many scheduling turns an advertisement gets before the count is taken. Time is
/// paused in these tests, so each turn costs nothing and only runs the driver until it
/// parks again; a busy machine cannot turn a slow announce into a passing silence.
Expand Down
15 changes: 14 additions & 1 deletion rs/moq-net/src/ietf/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,8 @@ pub(super) struct Subscriber<S: crate::transport::poll::Session> {
/// subscriber asks for its scope and mounts the replies under the root.
///
/// Asked unconditionally: a peer with nothing to advertise answers with an empty set,
/// which costs one stream.
/// which costs one stream. [`Subscriber::run_subscribe_namespace`] holds back the empty
/// prefix from a foreign draft-14/15 peer.
pub(super) fn subscribe_prefixes(origin: &origin::Producer) -> Vec<PathOwned> {
crate::model::interest_prefixes(&origin.allowed())
}
Expand Down Expand Up @@ -851,6 +852,18 @@ where
let declared = self.peer_setup.get().await;
let hidden = declared.hidden;

// Draft-16 is the first to allow a zero-field namespace, so the empty prefix is a
// protocol violation on draft-14/15. A peer that never declared MoQ Solicit is not
// ours: it may enforce that, and it tells us unasked anyway. One that declared it
// accepts the empty prefix and only tells when asked, so it still gets one.
if prefix.is_empty()
&& declared.solicit.is_none()
&& matches!(self.version, Version::Draft14 | Version::Draft15)
{
tracing::debug!(version = ?self.version, "not asking a foreign peer for the empty namespace");
return Ok(());
}

let request_id = self.control.next_request_id(&self.runtime).await?;

// Draft-18+ uses SUBSCRIBE_NAMESPACE (0x50); earlier drafts use the legacy
Expand Down
Loading