diff --git a/js/net/src/lite/connection.test.ts b/js/net/src/lite/connection.test.ts index 4412d0194e7..37685e6d53a 100644 --- a/js/net/src/lite/connection.test.ts +++ b/js/net/src/lite/connection.test.ts @@ -9,11 +9,12 @@ import { SessionCode, SessionError } from "../error.ts"; import { createMockTransportPair, type MockTransport, manual, settlesWithin, textFrame } from "../mock.ts"; import { Producer } from "../origin.ts"; import * as Path from "../path.ts"; -import { acceptBudget, Stream, Writer } from "../stream.ts"; +import { acceptBudget, Readers, Stream, Writer } from "../stream.ts"; import { Timescale } from "../time.ts"; import { wireOf } from "../wire.ts"; -import { type AnnounceBroadcast, encodeAnnounceBroadcast } from "./announce.ts"; +import { type AnnounceBroadcast, decodeAnnounceBroadcast, encodeAnnounceBroadcast } from "./announce.ts"; import { AnnounceStream } from "./announce_stream.ts"; +import { AuthMessage, AuthOk } from "./auth.ts"; import { Connection, probeLevel } from "./connection.ts"; import { Fetch } from "./fetch.ts"; import { Goaway } from "./goaway.ts"; @@ -1052,8 +1053,30 @@ for (const [name, violate] of [ [ "a reset Announce Stream", async (pair) => { + // The client answers once its peer grants its credential. + const auth = await Stream.accept(pair.server, Version.DRAFT_07); + if (!auth || (await auth.reader.u53()) !== StreamId.Auth) + throw new Error("the peer never presented a credential"); + await AuthMessage.decode(auth.reader, Version.DRAFT_07); + const all = new Path.Patterns([Path.Pattern.all()]); + await new AuthOk(all, all).encode(auth.writer, Version.DRAFT_07); const { writer, send } = await announceStream(pair); await send({ status: "request", more: false, remove: [], add: [{ prefix: ROOM, hidden: false }] }); + // A reset discards what the peer has not read, and a stream whose type byte is lost + // is not known to be an Announce Stream, so it cannot break the session. Reset only + // once the ANNOUNCE_OK answering the request shows the stream was identified. + const readers = new Readers(pair.server, Version.DRAFT_07); + try { + for (;;) { + const stream = await readers.next(); + if (!stream) throw new Error("the peer never answered"); + if ((await stream.u53()) !== DataType.Announce) continue; + expect(await decodeAnnounceBroadcast(stream, Version.DRAFT_07)).toEqual({ status: "ok" }); + break; + } + } finally { + readers.close(); + } writer.reset(new Error("gone")); }, ], diff --git a/quest/m0/test-flakes-3/js-announce-reset.md b/quest/m0/test-flakes-3/js-announce-reset.md deleted file mode 100644 index fe06e17feda..00000000000 --- a/quest/m0/test-flakes-3/js-announce-reset.md +++ /dev/null @@ -1,23 +0,0 @@ -# [S] js/net's reset Announce Stream test closes the session under load - -## Goal - -`js/net/src/lite/connection.test.ts`'s "a reset Announce Stream closes -moq-lite-07 with PROTOCOL_VIOLATION" passes every loaded `just check`. - -## Plan - -Found 2026-11-17 by `just check` on -[moq-dev/moq#8996](https://github.com/moq-dev/moq/pull/8996), whose change -touches no JS. Under the loaded check it hit bun's 5000 ms test timeout: the -session never closed. Run alone it passed 15 times in a row. - -A timeout, not a wrong code, means the reset went unnoticed. Trace how the -connection reads the Announce Stream when the mock transport delivers the -reset before or alongside the ANNOUNCE_REQUEST it follows: if a path drops the -reset (a read that resolves with the message and never polls again, or a reset -raced against the stream's open), that is a bug in `js/net`, fixed there with -a regression test. Only if the trace shows the close is merely slow is the fix -in the test, by the epic's rules. - -Public API: none. Wire: none.