Skip to content

fix(server): cap reactionsStore at 1000 entries to prevent memory exhaustion [NSoC'26]#144

Open
anshul23102 wants to merge 1 commit into
Shriii19:masterfrom
anshul23102:fix/139-reactions-store-cap
Open

fix(server): cap reactionsStore at 1000 entries to prevent memory exhaustion [NSoC'26]#144
anshul23102 wants to merge 1 commit into
Shriii19:masterfrom
anshul23102:fix/139-reactions-store-cap

Conversation

@anshul23102
Copy link
Copy Markdown

Description

reactionsStore was a plain object with no size cap or eviction policy. Every unique messageId added a permanent entry. Over time, as messages accumulated and reactions were added to many distinct message IDs, the store grew without limit. A user who sent many messages or triggered reactions on many unique IDs could exhaust process heap memory.

Related Issue

Closes #139

Type of Change

  • Bug fix (memory leak)

Root Cause

const reactionsStore = {} had no maximum entry count and no eviction logic. Entries were never deleted, even after their cooldown window long passed.

Changes Made

File Change
backend/server.js Added MAX_REACTION_ENTRIES = 1000 constant with explanatory comment
backend/server.js In the "react" handler: before inserting a new messageId, if the store is at capacity the oldest key is deleted first

Screenshots or Demo

Not applicable (backend-only change).

Testing Done

  • After 1000 unique messageIds have reactions, adding a reaction to a new message evicts the oldest entry, keeping Object.keys(reactionsStore).length at 1000.
  • Reactions on existing message IDs (already in the store) work normally; they do not trigger eviction.
  • Toggle behavior (add/remove reaction) is unaffected.

Checklist

  • I have read the CONTRIBUTING.md and followed its guidelines
  • My code follows the style and formatting of this project
  • I have tested my changes locally and they work as expected
  • No unnecessary files modified outside the scope of this issue
  • There are no merge conflicts with the base branch
  • This PR is linked to the correct issue
  • I have not used any AI-generated content in this PR

NSoC Label Request

@Shriii19 could you please add the appropriate NSoC '26 label to this PR? Thank you!

…memory growth [NSoC'26]

reactionsStore was a plain object with no size cap or eviction policy.
Every unique messageId added a permanent entry. A user who sent many
messages or reacted to many unique message IDs could grow the object
without limit, eventually exhausting process heap.

Added MAX_REACTION_ENTRIES = 1000. When a new messageId arrives and the
store is already at capacity, the oldest key is deleted before inserting
the new entry. This keeps memory bounded without affecting reactions on
recently active messages.

Closes Shriii19#139
@vercel
Copy link
Copy Markdown

vercel Bot commented May 31, 2026

@anshul23102 is attempting to deploy a commit to the shreemp194-gmailcom's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Copy Markdown

👋 Thank you for opening this pull request! I will review your changes and assist you soon.

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.

[Bug][Level 2] backend/server.js: reactionsStore object grows without bound, causing unbounded memory growth from message reactions

1 participant