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
3 changes: 1 addition & 2 deletions js/net/src/connection/reload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,7 @@ test("a retired GOAWAY predecessor still closes by its handover cap", async () =

// A publication only a token's grant covers keeps that grant while the session drains, so
// closing the loop ends the tokens after the drain rather than cutting the final group.
// Quarantined pending quest/m0/test-flakes-2/reload-close-drain.md.
test.skip("closing the loop keeps the tokens until the session drains", async () => {
test("closing the loop keeps the tokens until the session drains", async () => {
const original = globalThis.WebTransport;
const clock = new Manual();
const installed = clock.install();
Expand Down
97 changes: 97 additions & 0 deletions js/net/src/lite/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,38 @@ function holdFins(transport: MockTransport, streams: "uni" | "incoming-bidi") {
};
}

// Once enabled, every write on a bidirectional stream the peer opens reaches the peer before
// the writer resumes a host task later, as when the write budget yields: a reply delivered
// while its writer still waits.
function yieldReplies(transport: MockTransport) {
let enabled = false;
const wrap = (writable: WritableStream<Uint8Array>) => {
const writer = writable.getWriter();
return new WritableStream<Uint8Array>({
async write(bytes) {
await writer.write(bytes);
if (enabled) await yieldNow();
},
abort: (reason) => writer.abort(reason),
close: () => writer.close(),
});
};
Object.defineProperty(transport, "incomingBidirectionalStreams", {
value: transport.incomingBidirectionalStreams.pipeThrough(
new TransformStream<WebTransportBidirectionalStream, WebTransportBidirectionalStream>({
transform(stream, controller) {
controller.enqueue({ readable: stream.readable, writable: wrap(stream.writable) });
},
}),
),
});
return {
enable: () => {
enabled = true;
},
};
}

// Buffer incoming unidirectional streams outside the transport, independently of when the
// connection accepts them: its accept budget may yield until after the session closes. QMux
// keeps a finished stream's unread bytes across a close, so the reads still owed land afterwards.
Expand Down Expand Up @@ -360,6 +392,71 @@ for (const [alpn, version] of [
}
});

// A lite-07 subscriber FINs once it read the tail, which can land while SUBSCRIBE_FINISH's
// write still waits; the final group's FIN still holds the close.
if (keepsSubscribeOpen(version)) {
test(`a subscriber FIN during the end's write still drains the final group over ${versionName(version)}`, async () => {
const pair = createMockTransportPair(alpn);
const fin = holdFins(pair.server, "uni");
const replies = yieldReplies(pair.server);
const origin = new Producer();
const broadcastRoute = origin.route(Path.from("room"));
const broadcast = broadcastRoute.broadcast;
const producer = broadcast.createTrack("video", { timescale: Timescale.MILLI });
const url = new URL("https://localhost/test");
const client = new Connection({ url, quic: pair.client, version });
const server = new Connection({
url,
quic: pair.server,
version,
publish: origin.consume(),
client: false,
});
const remote = wireOf(client).consume(Path.from("room"));
const track = remote.track("video").subscribe().ordered();
let closed = false;
void pair.server.closed.then(() => {
closed = true;
});
try {
const first = producer.appendGroup();
first.writeFrame(textFrame("first"));
first.finish();
const received = await track.nextGroup();
expect(await received?.readString()).toBe("first");
expect(await received?.readString()).toBeUndefined();
received?.close();

fin.enable();
const last = producer.appendGroup();
last.writeFrame(textFrame("last"));
last.finish();
expect(await (await track.nextGroup())?.readString()).toBe("last");
await fin.reached;
replies.enable();
producer.finish();
producer.close();
const closing = server.close();

expect(await track.nextGroup()).toBeUndefined();
await settle();
expect(closed).toBe(false);

fin.release();
await closing;
expect(closed).toBe(true);
} finally {
fin.release();
track.close();
remote.close();
client.abort();
server.abort();
broadcast.close();
origin.close();
}
});
}

// The peer's close can overtake the final group or, where it is the track's only end, the
// SUBSCRIBE FIN it sent first; the closing session reads them.
for (const overtaken of hasTrackStream(version) ? ["group"] : ["group", "fin"]) {
Expand Down
18 changes: 8 additions & 10 deletions js/net/src/lite/publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1675,16 +1675,7 @@ export class Publisher {
if (!(await sendEnd())) return false;
continue;
}
if (!(await drained())) {
// A lite-07 subscriber FINs once it read the finished track's tail, or once
// it wants nothing more. Either way the reply FIN goes out now and the groups
// still waiting for a slot are cancelled, but an opened stream may be a final
// group whose FIN is still being acknowledged, so a draining close still
// waits for it; a reader that wants none of it resets it.
if (keepsSubscribeOpen(this.version))
void this.owe(Promise.allSettled(groups).then(() => undefined));
return false;
}
if (!(await drained())) return false;
if (pendingDrops.length > 0) continue;
// Lite-07 keeps the stream open past SUBSCRIBE_FINISH: an update may still ask
// for the ended track's history, and the subscriber FINs once it wants nothing
Expand Down Expand Up @@ -1768,6 +1759,13 @@ export class Publisher {
}
} finally {
if (!finished) unsubscribe();
// A lite-07 subscriber FINs once it read the finished track's tail, or once it wants
// nothing more, even while a reply is still being written. Either way the groups still
// waiting for a slot are cancelled, but an opened stream may be a final group whose FIN
// is still being acknowledged, so a draining close still waits for it; a reader that
// wants none of it resets it.
if (keepsSubscribeOpen(this.version) && groups.size > 0)
void this.owe(Promise.allSettled(groups).then(() => undefined));
priority.close();
}
}
Expand Down
8 changes: 7 additions & 1 deletion quest/m0/test-flakes-2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ explains. That batch predates #7658's merge at 15:56Z, and no queue run since
has failed it, so it needs no child of its own (noted 2026-11-03,
`/quest-plan`).

The JS reload close-drain test lost a race in the lite-07 publisher: the
subscriber's FIN after reading the tail could land while a reply write, such as
SUBSCRIBE_FINISH, still yielded on the write budget. That exit stopped owing the
opened group streams, so a draining close aborted a final group whose FIN was
still in flight. Every exit now owes them, fixed by
[moq-dev/moq#8047](https://github.com/moq-dev/moq/pull/8047).

Added 2026-11-03 (maintainer, `/quest-plan`): five more merge-queue failures
from 2026-11-03 and early 2026-11-04 UTC, one child each.

Expand All @@ -106,7 +113,6 @@ 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
- [reload.test.ts's close-drain tests pass under load](/quest/m0/test-flakes-2/reload-close-drain.md) - the drain cases in `js/net`'s reload tests pass in loaded multi-file runs
- [dispatch-query's terminate test survives load](/quest/m0/test-flakes-2/dispatch-query-terminate.md) - `test_terminating_the_run_stops_the_running_phase` passes reliably under host load, re-enabled once fixed
- [Diagnose and re-enable the FFI datagram connection test](/quest/m0/test-flakes-2/ffi-datagram-roundtrip.md) - diagnose the default-connection timeout and re-enable the quarantined test
- [Test PulseAudio servers stay off the desktop's D-Bus](/quest/m0/test-flakes-2/pulse-dbus.md) - concurrent media runs on one desktop never collide on `org.PulseAudio1`
Expand Down
100 changes: 0 additions & 100 deletions quest/m0/test-flakes-2/reload-close-drain.md

This file was deleted.