Skip to content

Fix/issue 2087 report generation memory leak - #2096

Merged
Dev1822 merged 2 commits into
Dev1822:mainfrom
Vachhani-Tapan:fix/issue-2087-report-generation-memory-leak
Aug 31, 2026
Merged

Fix/issue 2087 report generation memory leak#2096
Dev1822 merged 2 commits into
Dev1822:mainfrom
Vachhani-Tapan:fix/issue-2087-report-generation-memory-leak

Conversation

@Vachhani-Tapan

Copy link
Copy Markdown

Fix: Memory Leak in Report Generation Service

Resolves#2087

Description

This PR fixes a critical memory leak that caused Node.js heap exhaustion (OOM/HTTP 502) when generating the Annual Consolidated Payroll Summary for large enterprise tenants.

Previously, the process used Model.find().lean() to buffer all records into memory synchronously.

Code Changes

  • Created backend/src/services/reporting.service.js containing generateAnnualConsolidatedPayrollPDF().
  • Replaced .lean() with MongoDB cursors (.cursor()).
  • Piped pdfkit's PDFDocument directly to the provided outputStream (e.g., an Express res object).
  • Processes documents sequentially via for await, rendering them immediately to the PDF stream and discarding them from RAM.

Verification

  • Tested streaming a large mock dataset to verify heap usage remains flat.
  • Ensured stream is properly closed on success and on error.

@vercel

vercelBot commented Aug 31, 2026

Copy link
Copy Markdown

@Vachhani-Tapan is attempting to deploy a commit to the Dev's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Dev1822Dev1822 added enhancement New feature or request ECSoC26 labels Aug 31, 2026
@Dev1822
Dev1822 merged commit 520ba4b into Dev1822:mainAug 31, 2026
5 of 20 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ECSoC26-L2ECSoC26enhancementNew feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Memory Leak in Report Generation Service

2 participants

@Vachhani-Tapan@Dev1822