Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade obs-store and fix memory leaks #5228

Merged
merged 1 commit into from
Sep 10, 2018

Conversation

ConnorChristie
Copy link

@ConnorChristie ConnorChristie commented Sep 10, 2018

This PR discovers and addresses two event emitter memory leaks:

  • In the main metamask controller whenever the menu is opened
  • When setting up the public config store whenever a new tab is opened

The memory usage before fixing these was not as high as the original issue stated but when I analyzed the heap dumps periodically, there were many objects not being garbage collected (old event emitters). And, I was not able to run the tests for very long but I do see a reduction in the live javascript memory and it's staying consistently low over time.

This fixes #4074

@danfinlay
Copy link
Contributor

This is such a big deal, I can't thank you enough. Reviewing now.

Copy link
Contributor

@danfinlay danfinlay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. I had a question, but it wasn't a criticism, just learning from it.

app/scripts/metamask-controller.js Show resolved Hide resolved
outStream,
(err) => {
configStream.destroy()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, I thought the stream would clean itself up. Great subtle catch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be redundant bc pump destroys on close
unless this is prevented by some duplex half-open state

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh yes, you are correct. The reason I thought I needed it was because the obs-store stream did not have a destroy method and when I added that, I thought I needed to manually call it.

But this call does not need to be in there, pump will call destroy automatically now that the destroy function is implemented.

@danfinlay danfinlay merged commit 9b3b704 into MetaMask:develop Sep 10, 2018
@bdresser
Copy link
Contributor

hey @ConnorChristie could you shoot me an email? have a question for you 😄 bobby.dresser@consensys.net

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.

Bug Bounty: High memory usage, over 2 GB taken by MetaMask
4 participants