[Bug]: File share retains full file buffers in RAM indefinitely causing V8 heap exhaustion

Open
#464 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@ydvvdinesh is already working on this.

Since Nov 11, 2026.

  • #465 by @ydvvdinesh — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
node.js, typescript

Research direction

Start with src/server/signalling/handlers/fileShare.ts and trace how uploaded files are stored and how GET /api/files/download serves them. The issue identifies the desired behavior: retain metadata and a disk path, release file buffers after saving, and stream downloads from disk. A pull request is already open against this issue; check its changes and status before taking it on.

Written by the indexing model from the issue text.

Description

bug
Bug Description

In src/server/signalling/handlers/fileShare.ts, fileStore = new Map<string, SharedFile>() retains full in-memory file buffers (data: Buffer) in RAM indefinitely, even after the file has already been saved to the host disk. Because Rein permits file uploads up to 512 MB (MAX_FILE_BYTES = 512 * 1024 * 1024), uploading 2–3 files quickly exhausts the Node.js V8 heap (~1.4 GB to 2 GB) and causes the server process to crash with FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory, disconnecting all active WebRTC sessions.

Furthermore, downloading files by fileId via GET /api/files/download?fileId=<id> served the file using res.end(file.data), bypassing stream backpressure.

Steps to Reproduce
  1. Start the Rein server.
  2. Upload two large files (e.g., 400–500 MB video/archive files) via /api/files/upload.
  3. Observe Node.js memory footprint ballooning over 1.5 GB.
  4. Server crashes with JavaScript heap out of memory error.
Expected Behavior
  • Uploaded file data should be written to host disk and released from memory immediately for garbage collection.
  • fileStore should only hold metadata and the local file path.
  • fileId downloads should stream file chunks directly from disk using fs.createReadStream.
Desktop Operating System

Windows 11

Client OS and browser

Any (iOS Safari, Android Chrome, desktop browser)

Rein Version

1.0.0

Console Logs / Error Messages (Optional)

Screenshots / Recordings (Optional)

No response

Checklist
  • I have searched for existing issues to avoid duplicates
Dominant language
TypeScript
Stars
55
Forks
120
Avg merge
4d 5h
Merged PRs (30d)
24

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AOSSIE-Org/Rein

All issues in AOSSIE-Org/Rein

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.