Skip to content

Bug: Unbounded Memory Growth in Message Store Causing OOM Crashes #1092

@deepak0x

Description

@deepak0x

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions