diff --git a/js/net/src/ietf/request_stream.test.ts b/js/net/src/ietf/request_stream.test.ts index 9abf37f99b3..6d5f85fb36e 100644 --- a/js/net/src/ietf/request_stream.test.ts +++ b/js/net/src/ietf/request_stream.test.ts @@ -1,6 +1,6 @@ -import { expect, spyOn, test } from "bun:test"; +import { expect, mock, spyOn, test } from "bun:test"; import { Manual, Milli, Nano } from "@moq/clock"; -import { ProtocolViolation, SessionCode, StreamCode, StreamError } from "../error.ts"; +import { NoStreamCredit, ProtocolViolation, SessionCode, StreamCode, StreamError } from "../error.ts"; import { Reader, Stream } from "../stream.ts"; import { Deadline, REQUEST_TIMEOUT_MS } from "../util/deadline.ts"; import * as Varint from "../varint.ts"; @@ -196,3 +196,60 @@ test("a request's deadline ends it through the request, so later ends do nothing installed.close(); } }); + +test("a request opening after its deadline is aborted through its owner once and never sends", async () => { + const clock = new Manual(); + const installed = clock.install(); + const owners: RequestStream[] = []; + const abort = RequestStream.prototype.abort; + const ownerAborts = spyOn(RequestStream.prototype, "abort").mockImplementation(function ( + this: RequestStream, + err: unknown, + ) { + owners.push(this); + abort.call(this, err); + }); + try { + const write = mock((_chunk: Uint8Array) => {}); + const stream = new Stream({ + readable: new ReadableStream(), + writable: new WritableStream({ write }), + version: Version.DRAFT_18, + }); + const aborts = spyOn(stream, "abort"); + const opening = Promise.withResolvers(); + const session = { + version: Version.DRAFT_18, + client: true, + openBi: () => opening.promise, + } as unknown as Session; + const deadline = new Deadline(); + const send = mock((request: RequestStream) => request.writer.u8(1)); + const sending = RequestStream.open(session, deadline).then(send); + const answer = deadline.wait(sending).catch((e: unknown) => e); + await clock.advance(Nano.fromMilli(Milli(REQUEST_TIMEOUT_MS))); + const err = await answer; + expect(err).toBeInstanceOf(NoStreamCredit); + expect(ownerAborts).not.toHaveBeenCalled(); + expect(aborts).not.toHaveBeenCalled(); + + opening.resolve(stream); + await expect(sending).rejects.toBe(err); + expect(ownerAborts).toHaveBeenCalledTimes(1); + expect(ownerAborts.mock.calls[0]?.[0]).toBe(err); + const [request] = owners; + expect(request).toBeInstanceOf(RequestStream); + await request.ended; + + // The caller's cleanup cannot reset the late stream a second time. + request.abort(new Error("abandoned")); + request.close(); + expect(aborts).toHaveBeenCalledTimes(1); + expect(aborts.mock.calls[0]?.[0]).toBe(err as NoStreamCredit); + expect(send).not.toHaveBeenCalled(); + expect(write).not.toHaveBeenCalled(); + } finally { + ownerAborts.mockRestore(); + installed.close(); + } +}); diff --git a/quest/m1/README.md b/quest/m1/README.md index 360826fa74b..f569dcddaab 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -193,7 +193,6 @@ per-frame CPU growth since #5926. - [A cancelled MoqTrackDemand wait never loses the next change](/quest/m1/demand-cancel-race.md) - cancelling a `MoqTrackDemand::wanted_changed` call, from any binding, never consumes a demand change - [moq-ffi reports an unsupported media configuration as a typed error](/quest/m1/ffi-unsupported-config.md) - `MoqAudioConsumer::subscribe` and the matching video subscribe fail with a typed "unsupported configuration" error - [A live keyframe interval change never outruns the declared HLS duration](/quest/m1/js-hls-keyframe-duration.md) - raising a live keyframe interval, even to infinite, never pushes a segment past the declared HLS target duration, and the browser interop cell asserts the catalog `hls` field -- [A request stream that opens after its deadline is aborted once and never sends](/quest/m1/js-request-deadline.md) - A `@moq/net` IETF request whose stream finishes opening only after its deadline fired is aborted exactly once, through its `RequestStream`, and never writes its request - [One Ed25519 public key type with one z-base-32 codec](/quest/m1/mesh-key-codec.md) - `moq_auth::mesh::EndpointId` is merged into `moq_sign::PublicKey` - [moqsink reports track demand only once the track is in the catalog](/quest/m1/moqsink-demand-catalog.md) - A `moqsink` request pad's `track-demand` stays null until its track is listed in the published catalog, and only then reports `wanted` - [A discontinuity before the first frame keeps the init's parameter sets](/quest/m1/mux-discontinuity-headers.md) - an avc3, hev1, or av01 track that marks a discontinuity before its first frame still publishes that first keyframe with its init's parameter sets diff --git a/quest/m1/js-request-deadline.md b/quest/m1/js-request-deadline.md deleted file mode 100644 index 8c52aff30e0..00000000000 --- a/quest/m1/js-request-deadline.md +++ /dev/null @@ -1,29 +0,0 @@ -# [XS] A request stream that opens after its deadline is aborted once and never sends - -## Goal - -A `@moq/net` IETF request whose stream finishes opening only after its -deadline fired is aborted exactly once, through its `RequestStream`, and -never writes its request. A test proves it. - -## Plan - -Decided 2026-10-31 (user, /quest-plan of the follow-ups from the 2026-10-31 -/quest-complete run), from -[moq-dev/moq#7355](https://github.com/moq-dev/moq/pull/7355). - -Milestone: ✅ m1 (moved from m2). Not chosen: m2. - -- [moq-dev/moq#7355](https://github.com/moq-dev/moq/pull/7355) (merged) routes a deadline failure through the owning `RequestStream` - (`js/net/src/ietf/request_stream.ts`, `js/net/src/util/deadline.ts`), so a - timed-out request is ended once. Its online review suggested one more test, - left as this follow-up: resolve the opening stream only after the deadline - expires, then assert the owner aborts it exactly once and the request bytes - are never written. -- Add it beside `request_stream.test.ts`'s "a request's deadline ends it - through the request" case. Fix the code if it fails. -- The deleted quest of the same name (one 10 s deadline from create to - answer) planned this reset; this quest only proves it through the new - owner. - -Public API: none. Wire: none.