Skip to content

fix: heap profiling, subscriber cleanup, and memory alerts for BE-088 - #1963

Open
Netty-kun wants to merge 1 commit into
StellarDevHub:mainfrom
Netty-kun:feat/issue-1835-be-088-memory-leak-prevention-node-js-heap
Open

Netty-kun wants to merge 1 commit into
StellarDevHub:mainfrom
Netty-kun:feat/issue-1835-be-088-memory-leak-prevention-node-js-heap

Conversation

@Netty-kun

Copy link
Copy Markdown

Overview

This PR adds heap-usage instrumentation and alerting to the backend, and tightens cleanup of collaboration-server state so long-running processes no longer accumulate retained references. The changes target slow heap growth that eventually leads to V8 OOM crashes.

Related Issue

Closes BE-088

Changes

🧠 Heap Instrumentation & Alerts

  • [MODIFY] backend/src/instrumentation.ts

    • Samples process.memoryUsage() and v8.getHeapStatistics() on a fixed interval.
    • Emits a warning-level health alert when heap usage exceeds 85% of heap_size_limit, so it fires before exhaustion.
    • Captures a heap snapshot on threshold breach for offline analysis.
  • [MODIFY] backend/src/infrastructure/structured-logger.service.ts

    • Routes the new heap alerts through the existing structured logger so they carry consistent fields.

🔌 Collaboration Server Cleanup

  • [MODIFY] backend/src/collaborationServer.ts
    • Removes disconnecting clients from WebSocket room subscriber maps on close/error.
    • Deletes empty room entries so rooms with no remaining subscribers do not persist.
    • Detaches per-socket event listeners when a connection ends.

🧾 Request Logging

  • [MODIFY] backend/src/middleware/requestLogger.ts
    • Avoids retaining request/response references in log closures after the response finishes.

Verification Results

Changes were reviewed against the issue's acceptance criteria. A 24-hour load test has not been run as part of this PR; the plateau behavior should be confirmed in a staging soak test before the issue is closed.

Acceptance Criteria Status
Heap usage plateaus under continuous 24-hour load ⏳ Pending staging soak test
WebSocket subscriber maps dereference disconnecting clients ✅ Cleanup on close/error in collaborationServer.ts
Automated health alerts fire before memory exhaustion ✅ Alert at >85% of max old space in instrumentation.ts

Closes #1835

@vercel

vercel Bot commented Nov 23, 2026

Copy link
Copy Markdown

@Netty-kun is attempting to deploy a commit to the Ayomide Adeniran's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Nov 23, 2026

Copy link
Copy Markdown

@Netty-kun Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Netty-kun
Netty-kun force-pushed the feat/issue-1835-be-088-memory-leak-prevention-node-js-heap branch from e36d6cb to 3717234 Compare November 24, 2026 23:09
@drips-wave

drips-wave Bot commented Nov 24, 2026

Copy link
Copy Markdown

Warning

Possible malicious code: please review before merging.

An automated security scan flagged files in this pull request that appear to contain malicious code. Code like this can run automatically when a project is opened in an editor or its dependencies are installed, so it could compromise the machine of anyone who checks out this branch.

Automated scans can be wrong, so this may be a false positive. Maintainers: please review the flagged files carefully before merging, on GitHub in your browser rather than by checking out the branch. The malicious part is often hidden far off to the right of an ordinary-looking line, so scroll sideways through each file.

@Netty-kun: this pull request adds or changes these files, possibly without your knowledge. Malware like this spreads by adding itself to repositories on machines it has infected, so your machine and / or GitHub account may be compromised. Please review your machine for a possible malware infection, and rotate your GitHub credentials / SSH keys as needed.

Flagged files at commit 3717234:

Only merge once you're confident these files are safe.

ℹ️ Posted automatically by Drips Wave. Questions? Contact support@drips.network.

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.

[BE-088] Memory Leak Prevention: Node.js Heap Profiling & Buffer Management

1 participant