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
71 changes: 70 additions & 1 deletion js/net/src/lite/datagram-tracks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import { yieldNow } from "@moq/clock";
import { hostTime } from "@moq/clock/test";
import { Signal } from "@moq/signals";
import { accept, connect } from "../connection/index.ts";
import { SessionCode } from "../error.ts";
import { hooks } from "../internal.ts";
import { createMockTransportPair, type MockTransport } from "../mock.ts";
import { Producer as Origin } from "../origin.ts";
import * as Path from "../path.ts";
import { sendOrder } from "../priority.ts";
import { Writer } from "../stream.ts";
import { Timescale, Timestamp } from "../time.ts";
import { Budget } from "../util/yield.ts";
import { wireOf } from "../wire.ts";
import { ALPN_04, ALPN_05, ALPN_06, ALPN_07_WIP } from "./version.ts";
import { DataType } from "./stream.ts";
import { ALPN_04, ALPN_05, ALPN_06, ALPN_07_WIP, Version } from "./version.ts";

const url = new URL("https://localhost/datagrams");
const path = Path.from("live");
Expand Down Expand Up @@ -492,6 +496,71 @@ for (const alpn of [ALPN_05, ALPN_06, ALPN_07_WIP]) {
});
}

// A peer's protocol violation fails the session at once, without the drain a close gets. A lite-05/06
// datagram track whose SUBSCRIBE_FINISH was accepted keeps that end, even while its FIN lags.
for (const [alpn, version] of [
[ALPN_05, Version.DRAFT_05],
[ALPN_06, Version.DRAFT_06],
] as const) {
test(`${alpn}: a duplicate SETUP after a datagram track's end keeps the end`, async () => {
const source = new Origin();
const publication = source.route(path, { hidden: true });
const datagrams = publication.broadcast.createDatagrams("audio");
publication.announce();
const pair = createMockTransportPair(alpn);
// Once armed, the publisher's FINs on the request streams it accepts never leave.
let holding = false;
const holdFin = (writable: WritableStream<Uint8Array>) => {
const writer = writable.getWriter();
return new WritableStream<Uint8Array>({
write: (bytes) => writer.write(bytes),
abort: (reason) => writer.abort(reason),
close: () => (holding ? new Promise<void>(() => {}) : writer.close()),
});
};
Object.defineProperty(pair.server, "incomingBidirectionalStreams", {
value: pair.server.incomingBidirectionalStreams.pipeThrough(
new TransformStream<WebTransportBidirectionalStream, WebTransportBidirectionalStream>({
transform: (bidi, controller) =>
controller.enqueue({ readable: bidi.readable, writable: holdFin(bidi.writable) }),
}),
),
});
const [client, server] = await Promise.all([
connect({ url, transport: pair.client }),
accept({ url, transport: pair.server, publish: source.consume() }),
]);
const remote = wireOf(client).consume(path);
const reader = remote.datagrams("audio");
reader.setPriority(5);
const accepted = Promise.withResolvers<void>();
const endTrack = hooks.endTrack;
const spy = spyOn(hooks, "endTrack").mockImplementation((...args) => {
endTrack(...args);
accepted.resolve();
});
try {
await reader.info();
while (datagrams.priority.peek() !== 5) await datagrams.priority.changed();
holding = true;
datagrams.finish();
await accepted.promise;
const writer = await Writer.open(pair.server, { version });
// The client claims the Setup Stream on its type, so the type alone is the duplicate.
await writer.u53(DataType.Setup);
expect((await pair.client.closed).closeCode).toBe(SessionCode.ProtocolViolation);
expect(await reader.recv()).toBeUndefined();
} finally {
spy.mockRestore();
reader.close();
remote.close();
client.abort();
server.abort();
source.close();
}
});
}

// Holds back what the publisher writes on the next request stream it accepts once armed, until
// released: that subscription's answer stays outstanding while everything else flows.
function holdNextAnswer(transport: MockTransport): { arm(): void; release(): void } {
Expand Down
5 changes: 4 additions & 1 deletion js/net/src/lite/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2808,9 +2808,12 @@ export class Subscriber {
close(err: Error = new SessionError(SessionCode.Cancel)) {
this.#closed.abort(err);

for (const { track, finished } of this.#subscribes.values()) {
for (const { track, finished, end, datagrams } of this.#subscribes.values()) {
if (finished) track.finish();
track.abort(err);
// Lite-05/06: the stream track's end is its datagrams' end. An abort after the declared
// end settled ends it cleanly, even while the FIN that would finalize it is in flight.
if (datagrams && end !== undefined && hooks.trackReleased(track).peek() === null) datagrams.ended = true;
}

this.#subscribes.clear();
Expand Down
6 changes: 5 additions & 1 deletion quest/m0/test-flakes-2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ publisher's write budget yielded under load while writing SUBSCRIBE_FINISH, past
the case's microtask drain. [moq-dev/moq#8000](https://github.com/moq-dev/moq/pull/8000)
stubbed that budget, merging after the quarantine was written. The case was
re-enabled in [moq-dev/moq#8110](https://github.com/moq-dev/moq/pull/8110).
Its follow-up: a peer's protocol violation, such as a duplicate SETUP, fails the
session without the drain a close gets, so a lite-05/06 datagram track whose
SUBSCRIBE_FINISH arrived before its FIN aborted with the session's error. Its
datagrams now finish whenever the stream track's settled end survives the abort,
fixed by [moq-dev/moq#8157](https://github.com/moq-dev/moq/pull/8157).

`sh/dispatch-query.test.py`'s terminate test was never load-bound. A TERM
landing just after the dispatcher's `wait -n` returned left Bash marking the
Expand All @@ -153,6 +158,5 @@ Public API: none. Wire: none.
## Required

- [Fallback playback](/quest/m0/test-flakes-2/ietf22-fallback.md) - a browser viewer follows a fallback within the media lane's bound without dropping its session
- [The datagram-end close follow-up](/quest/m0/test-flakes-2/datagram-end-close.md) - investigate whether duplicate SETUP can override an accepted lite-06 SUBSCRIBE_END during shutdown
- [moq-transcode's idle-rung cancel test survives load](/quest/m0/test-flakes-2/transcode-idle-rung-cancel.md) - `cancelling_an_idle_rung_reports_cancel` stops seeing `serve` return before its abort lands
- [moq-gst's sink-restart pad test survives load](/quest/m0/test-flakes-2/gst-sink-restart-pads.md) - `a_moqsink_restart_keeps_pads_when_caps_arrive_at_different_times` keeps its pads under load
105 changes: 0 additions & 105 deletions quest/m0/test-flakes-2/datagram-end-close.md

This file was deleted.

2 changes: 1 addition & 1 deletion quest/m1/ts-reliability/pcr-jump-flag.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ Validate actual-PCR-jump flags in the remaining TS recovery interop coverage.

Decided 2026-11-06 (maintainer, /quest-unblock): ✅ Continue the actual-PCR-jump approach. Not chosen: rethink; drop the PR.

Decided 2026-11-06 (maintainer, /quest-unblock): ✅ Reproduce and fix the Rust `with_delay` schedule replacement in this PR. Hand the unrelated JS decoded-end/session-failure finding to [datagram-end-close](/quest/m0/test-flakes-2/datagram-end-close.md). Not chosen: fixing both findings here.
Decided 2026-11-06 (maintainer, /quest-unblock): ✅ Reproduce and fix the Rust `with_delay` schedule replacement in this PR. Hand the unrelated JS decoded-end/session-failure finding to the datagram-end close quest, fixed by [moq-dev/moq#8157](https://github.com/moq-dev/moq/pull/8157). Not chosen: fixing both findings here.

Decided 2026-11-06 (maintainer, /quest-unblock): ✅ Construction-only delay supersedes runtime updates. TS Export and Release take delay when constructed, so retained state never changes its delay basis. Not chosen: full runtime retiming; landing without the fix.
Loading