stack/apps/backend/scripts/verify-data-integrity
Aman Ganapathy 1d00ed2c64
[Fix]: Investigate Memory Leak on Verify Data Integrity (#1269)
### Context
We encountered an out of memory error when running verify-data-integrity
against the prod database. This was the error:
`FATAL ERROR: Ineffective mark-compacts near heap limit Allocation
failed - JavaScript heap out of memory`. This was one of the things
preventing verify-data-integrity from running successfully in prod.

### Summary of Changes
Local stress testing with constrained heap and memory telemetry revealed
that the rise in used heap memory was directly proportional to the
number of api calls. Investigation revealed that the `currentOutputData`
array was growing with each api call and was kept in memory. Since it
was still being appended to, it was actively kept in the heap. We
refactor the script to no longer use it, and for the two flags
`--save-output` and `--verify-output` that used it before, we refactor
them to not need to. `--save-output` now streams responses to disk as
JSONL and `--verify-output` now compares each response immediately and
discards it.
We also note a potential source of a future memory leak in the
`allUsers` array that is populated in memory for each project. We
refactor to paginate instead. Note that this didn't cause a memory leak
on local, this is a preventive measure.

### Out of Scope
fetching all transactions in the payments section of the script is
another potential cause for concern, but since the payments section of
the script will be refactored soon, we defer that discussion.
2026-03-23 08:55:10 -07:00
..
api.ts [Fix]: Investigate Memory Leak on Verify Data Integrity (#1269) 2026-03-23 08:55:10 -07:00
index.ts [Fix]: Investigate Memory Leak on Verify Data Integrity (#1269) 2026-03-23 08:55:10 -07:00
payments-verifier.ts verify payment transactions integrity (#1128) 2026-01-27 21:17:43 +00:00
recurse.ts --no-bail for verify-data-integrity script 2026-01-28 13:53:28 -08:00
stripe-payout-integrity.ts verify payment transactions integrity (#1128) 2026-01-27 21:17:43 +00:00