facebook / memlab

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

memlab API findLeaks sometimes freeze on step calculateDominatorNodesFromPostOrder() #48

Closed abay-ibrayev closed 1 year ago

abay-ibrayev commented 1 year ago

Hi, I'm using memlab@1.1.30.

Facing issue: tests freezes on particular pages in our app (not everytime). I suppose that problem related to some objects in snapshot that couldn't parse by memlab.

In memlab code (step where freezes): /packages/core/src/paths/TraceFinder.ts#L582

Provided in attach zip with my data/cur files for failed test.

Thanks in advance for any help!

JacksonGL commented 1 year ago

@ibrayevabay Thanks for reporting this issue with the heap snapshots. For a temporarily fix to unblock you, please add the following code snippet before this line:

if (postOrderIndex >= nodeCount) {
  postOrderIndex--;
}

After applying the temp fix, it should unfreeze the execution. The memory leaks detected will still be correct, but the retained size may be inaccurate.

I need to spend some time to investigate the heap snapshot and come up with a proper fix.

JacksonGL commented 1 year ago

@ibrayevabay Proper fix here

return !!referrer; --> return !referrer;

Commit on the way, may take a while (internal approving + sync to GitHub).

abay-ibrayev commented 1 year ago

@JacksonGL Hi, thanks for the response and quick resolve this issue, very appreciate it <3 It's not blocking me right now, so will wait new version with fixes, thanks!

abay-ibrayev commented 1 year ago

Hi. could u please update me when fix will be released. Issue closed, so I expected fixes to be in 1.1.33 version. But still not fixed there:

Screen Shot 2022-10-26 at 17 27 58
JacksonGL commented 1 year ago

Hi @ibrayevabay, the fix is already in GitHub and should have been included in memlab@1.1.33: https://github.com/facebook/memlab/blob/dc2b0f43371fb1ac1c59e377d4f88497f5883085/packages/core/src/lib/Utils.ts#L947

abay-ibrayev commented 1 year ago

Hmmm, very strange. I reinstalled lib 3 times. Cleaned yarn cache, installed everything from scratch, and still see in my project node_modules old implementation:

function hasOnlyWeakReferrers(node) {
    const referrer = node.findAnyReferrer((edge) => edge.type !== 'weak' && edge.type !== 'shortcut');
    return !!referrer;
}

Could u please recheck, may be this commit not included in 1.1.33? Thanks in advance!

JacksonGL commented 1 year ago

@ibrayevabay I created a test project, npm installed memlab and the fix was included in the installed package. Make sure you have deleted package-lock.json and yarn.lock. Also double check the version of memlab (1.1.33) and memlab@core (1.1.16) in the node_modules directory.