RocketChat / RocketChat/EmbeddedChat

Bug: Unbounded Memory Growth in Message Store Causing OOM Crashes

Open
#1,092 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
165
Forks
381
Avg merge
1d 2h
Merged PRs (30d)
1

Description

A memory management issue exists in the message store where messages are accumulated in memory without any upper bound. In active or high-traffic channels, this causes unbounded memory growth, eventually leading to Out-Of-Memory (OOM) crashes, especially on mobile devices.


Observed Behavior

The setMessages function appends incoming messages directly to the existing message array:

[...state.messages, ...newMessages]

There is no cap or eviction strategy applied. As a result:

  • Messages accumulate indefinitely
  • Memory usage grows linearly with channel activity
  • Old messages are never released from memory

Why this is not good

  • Mobile environments (React Native) have limited memory
  • An ever-growing array of message objects prevents garbage collection
  • Eventually, the JavaScript heap fills up
  • The application crashes with an OOM error

This makes the application unstable and unusable for users in busy channels.


Steps to Reproduce

  1. Connect to a high-volume channel (for example, general).
  2. Leave the application running for an extended period (overnight).
  3. Monitor memory usage using profiling tools.

Expected Behavior

The message store should enforce a bounded memory strategy, such as:

  • A fixed maximum number of messages (for example, 500)
  • Dropping the oldest messages when the limit is exceeded
  • Implementing a circular buffer or sliding window approach

This ensures predictable memory usage regardless of channel activity.

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Start at the message store's setMessages function, where the issue identifies direct accumulation with [...state.messages, ...newMessages]. Reproduce the growth in a high-volume channel and monitor memory usage; done means messages are bounded, older entries are released, and memory remains predictable during extended activity.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react-native
Domain
mobile-dev, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.