diff --git a/js/net/src/origin.test.ts b/js/net/src/origin.test.ts index 6a8535450ce..814a2a44635 100644 --- a/js/net/src/origin.test.ts +++ b/js/net/src/origin.test.ts @@ -470,6 +470,22 @@ test("a received route its announcer ends ends, and one its session loses goes o origin.close(); }); +test("a route received through a scoped handle goes offline when the handle closes", async () => { + const origin = new Producer(); + const announced = origin.consume().routes(); + + const scoped = origin.scope(Path.empty(), new Path.Patterns([Path.Pattern.all()])); + const route = wireOf(scoped).receive(Path.from("room"), WireRoute.default); + expect(await announced.next()).toMatchObject({ prefix: Path.from("room"), kind: "start" }); + + scoped.close(); + expect(await announced.next()).toMatchObject({ prefix: Path.from("room"), kind: "offline" }); + route.close(); + + announced.close(); + origin.close(); +}); + test("announced keeps a broader covering route at its prefix", async () => { const origin = new Producer(); const consumer = origin.consume(); diff --git a/js/net/src/origin.ts b/js/net/src/origin.ts index cb36224a43e..731c2f8a1f8 100644 --- a/js/net/src/origin.ts +++ b/js/net/src/origin.ts @@ -1688,16 +1688,15 @@ export class Producer implements Table { this.#state.rebuildOriginated(); this.#state.refreshPrefix(prefix); }; + // A received route torn down by any path (its handle, or the scoped handle it came through) + // was lost with its session; only its announcer ending it on the wire withdraws it. + let lost = !originated; const release = this.#hold(() => { + if (!ended) entry.lost = lost; ended = true; this.#state.servers.delete(server); remove(() => server.close()); }); - // A received route its handle closes was lost with its session, unless its announcer ended it. - const close = (lost: boolean) => { - if (!ended) entry.lost = lost; - release(); - }; // A route made after its origin (or this handle) closed is born retracted. if (this.#borrowed?.closed || this.#state.closed.peek() !== undefined) { ended = true; @@ -1752,8 +1751,11 @@ export class Producer implements Table { }, announced: () => inserted && this.#state.closed.peek() === undefined, change: (changed) => update(WireRoute.normalize({ ...entry.route.peek(), ...changed })), - close: () => close(!originated), - end: () => close(false), + close: release, + end: () => { + lost = false; + release(); + }, info: () => (inserted && this.#state.closed.peek() === undefined ? entry.route.peek() : undefined), update: (next) => { // A route naming no instance keeps the one it serves. diff --git a/quest/m1/offline-cursor-fallback.md b/quest/m1/offline-cursor-fallback.md index 921589a9c15..622917f34e6 100644 --- a/quest/m1/offline-cursor-fallback.md +++ b/quest/m1/offline-cursor-fallback.md @@ -34,7 +34,3 @@ Caused by: [moq-dev/moq#8375](https://github.com/moq-dev/moq/pull/8375), which introduced the offline reason and left this branch on End. Public API: none. Wire: none. - -## Related - -- [A scoped JS handle that closes reports its routes offline](/quest/m1/offline-js-handle.md) - the same misreport in `js/net` diff --git a/quest/m1/offline-js-handle.md b/quest/m1/offline-js-handle.md deleted file mode 100644 index f663cdb86bd..00000000000 --- a/quest/m1/offline-js-handle.md +++ /dev/null @@ -1,39 +0,0 @@ -# [S] A scoped JS handle that closes reports its routes offline - -## Goal - -In `@moq/net`, routes a session received through a scoped `Producer` go -offline when that scoped handle closes while the parent origin stays open. -The parent's announcement reader emits `offline`, not `end` or `absent`, -unless the announcer ended the route on the wire. - -## Plan - -Planned 2026-11-10 (maintainer, /quest-plan on lite-07 routing). Milestone: -✅ m1 (rejected: m2 in the routes epic; m0). - -Found by the automated review of -[moq-dev/moq#8375](https://github.com/moq-dev/moq/pull/8375), posted fifteen -minutes before it merged and never addressed. Closing the scoped handle runs -the raw callbacks `#hold` registered (`js/net/src/origin.ts`, about line -1695) and skips `close(lost)`, so received entries keep `lost = false` and -the reader reports a withdrawal. A later route close cannot repair it, -because `ended` is already true. - -Reproduce it first in `js/net/src/origin.test.ts`: receive a route through a -scoped handle, close the handle, and read the parent's announcements. Then -put the reason in the shared release transition, so a received route's -teardown defaults to offline and only an explicit wire end selects -withdrawal. - -Compare with Rust's scoped teardown and say in the PR whether it has the same -gap; if it does, fix it in the same PR, as `moq-net` and `js/net` stay in -step. - -Caused by: [moq-dev/moq#8375](https://github.com/moq-dev/moq/pull/8375). - -Public API: none. Wire: none. - -## Related - -- [A scoped cursor reports a lost route as offline when a broader route takes over](/quest/m1/offline-cursor-fallback.md) - the same misreport in the Rust cursor