facebook / memlab

A framework for finding JavaScript memory leaks and analyzing heap snapshots
https://facebook.github.io/memlab/
MIT License
4.32k stars 116 forks source link

memlab find-leaks OOM #122

Closed johnhok closed 2 weeks ago

johnhok commented 2 weeks ago

I have a set of snapshots that seem to generate node OOM when executing memlab find-leaks --snapshot-dir ./oom.

I see the memory usage of the node process climb to over 4GB before node hits OOM. Raising --max-old-space-size doesn't seem to help either. The problem doesn't always consistently fail with OOM on the same set of snapshots.

The largest heap out of the 3 snapshots is 160MB.

Here is a link to a zip of the snapshots:

https://drive.google.com/file/d/1KqBsoAOBkb-8LE5hsiNfucUM9DQF0jJk/view?usp=sharing

JacksonGL commented 2 weeks ago

It appears the OOM happens when memlab tries to serialize some leak traces with large script heap objects. To temporarily unblock yourself, you can comment out the loop here: https://github.com/facebook/memlab/blob/16b4d9a3f1d383b02a67a4d87596f8a16c0d1f86/packages/core/src/logger/LeakTraceDetailsLogger.ts#L60-L73

I will figure out a fix for this.

JacksonGL commented 2 weeks ago

@johnhok I've pushed a fix for this issue. Before I release it on npm, please let me know if you get any additional issues when you get a chance.

Here is the instruction on how to build it locally after checking out the recent fix: https://github.com/facebook/memlab?tab=readme-ov-file#development

You can run the locally built memlab using the following command:

node packages/memlab/bin/memlab find-leaks --snapshot-dir <dir>
johnhok commented 2 weeks ago

@JacksonGL I pulled down the latest changes and ran the CLI against the snapshots several times and it seemed to resolve the issue. I also don't see any additional issues against this set of heap snapshots after the changes.

I can run more tests against additional sets of data that I had trouble with previously tomorrow if you want some more exhaustive testing of the changes.

Thanks again for looking into the issue and resolving!

JacksonGL commented 2 weeks ago

@johnhok Thanks! The current fix simplified the serialization of a specific type of heap object. Since the web app you are testing exposed this issue, there might be other types of heap objects causing similar problems. It would be great to identify and fix any additional issues before releasing a new version.

johnhok commented 2 weeks ago

@JacksonGL I ran the updated tool against a few more snapshots from test runs that I have and was not able to replicate any other issues.

JacksonGL commented 2 weeks ago

@johnhok Released in memlab@1.1.51. Thanks for reporting this issue and help confirm the fix