Skip to content

room-node: fix convertPool worker lifecycle/validation and fastLoad shared buffer leaks - #442

Open
Pybsama wants to merge 1 commit into
Nehanth:mainfrom
Pybsama:fix/room-node-convert-pool-and-fastload-lifecycle
Open

Pybsama wants to merge 1 commit into
Nehanth:mainfrom
Pybsama:fix/room-node-convert-pool-and-fastload-lifecycle

Conversation

@Pybsama

@Pybsama Pybsama commented Dec 4, 2026

Copy link
Copy Markdown

Summary

Fixes worker-pool lifecycle/concurrency bugs in packages/room-node/convert.js and shared-buffer cleanup leaks on error paths in packages/room-node/fastload.js.

Changes

  • packages/room-node/convert.js:
    • Coalesce concurrent start() calls behind a single starting promise so simultaneous convert() / repackShared() calls do not spawn duplicate worker pools and leak the overwritten workers; if close() occurs mid-startup, immediately terminate newly created workers.
    • Track closed state in close(), reject in-flight waiting jobs so callers settle cleanly (falling back inline / returning null) instead of hanging forever, and prevent post-close calls from respawning workers.
    • Handle unexpected worker "exit" events (in addition to "error") by marking the pool broken, rejecting pending jobs, and terminating remaining workers instead of hanging indefinitely.
    • Validate repackShared inputs/outputs (n > 0, bytes.byteLength, and SharedArrayBuffer size checks on out.qs/out.sc) up front so malformed/undersized buffers return null without crashing a worker and breaking the entire pool.
  • packages/room-node/fastload.js:
    • Return acquired SharedArrayBuffer input buffers to the free list when readInto rejects (before downstream awaiters resume) or when inline fallback conversion throws.
    • Guard repack completion against closed so repacked entries are not counted/returned after close().
  • Regression tests: added tests in packages/room-node/test/convert_test.mjs and packages/room-node/test/fastload_test.mjs.

Verification

  • node --test packages/room-node/test/convert_test.mjs packages/room-node/test/fastload_test.mjs: 9 passed, 0 failed
  • npm run test:packages: 217 passed, 6 skipped, 0 failed
  • npm run test:runtime: 6/6 runtime checks passed

@Pybsama
Pybsama requested a review from Nehanth as a code owner December 4, 2026 14:40
@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