Skip to content

room-node: fix source sideFile HTTP status, prefetcher close/duplicate reads, fetchRange bounds, and localFileReader lanes/close race - #441

Open
Pybsama wants to merge 1 commit into
Nehanth:mainfrom
Pybsama:fix/room-node-source-prefetch-close-and-edge-cases
Open

Pybsama wants to merge 1 commit into
Nehanth:mainfrom
Pybsama:fix/room-node-source-prefetch-close-and-edge-cases

Conversation

@Pybsama

@Pybsama Pybsama commented Dec 4, 2026

Copy link
Copy Markdown

Summary

Fixes four edge-case bugs in packages/room-node/source.js:

  1. openModel() sideFile() HTTP error check: cfg() / tokJson() previously called fetchImpl(url).then((r) => r.json()) without checking r.ok, returning HTTP 4xx/5xx JSON error bodies as config/tokenizer data. Now throws Error("fetch <status> for <url>") when !r.ok.
  2. rangePrefetcher close(), duplicate planned reads, re-plan reset, and len === 0:
    • close() now clears reads, decrements held for buffered chunks, marks chunks dropped, and nulls c.p so settled chunk promises do not retain multi-GB Uint8Array buffers after close.
    • plan() resets reads and next, and tracks planned reference counts per off:len key so duplicate planned reads of the same range do not prematurely drop the chunk after the first read().
    • read(off, 0) returns an empty Uint8Array(0) and closed prefetchers return null.
  3. fetchRange() zero-length and invalid ranges: Validates 0 <= start <= end (finite) and returns new Uint8Array(0) immediately when end === start instead of sending an invalid Range: bytes=0--1 HTTP request.
  4. localFileReader lanes clamping and concurrent close() during open(): Clamps non-positive/non-finite lanes to >= 1 (preventing TypeError: Reduce of empty array with no initial value) and closes + rejects with reader is closed if close() occurs while fs.promises.open() is still pending.

Verification

  • Added 4 regression tests in packages/room-node/test/source_test.mjs (all 4 failed RED before fix, passed after fix).
  • node --check packages/room-node/source.js packages/room-node/test/source_test.mjs — clean.
  • node --test packages/room-node/test/source_test.mjs — 13 pass, 0 fail.
  • npm run test:packages — 217 pass, 0 fail, 6 skipped.
  • npm run test:runtime — protocol: 4, 6/6 checks passed (172 frames).

…e reads, fetchRange bounds, and localFileReader lanes/close race
@Pybsama
Pybsama requested a review from Nehanth as a code owner December 4, 2026 11:35
@vercel

vercel Bot commented Dec 4, 2026

Copy link
Copy Markdown

@Pybsama is attempting to deploy a commit to the nehanth's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant