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

Partially fix domain memory leak #499

Closed
wants to merge 1 commit into from
Closed

Partially fix domain memory leak #499

wants to merge 1 commit into from

Conversation

aheckmann
Copy link
Contributor

After the response is finished, remove the request and
response objects from the domain and prevent them from
remaining in the captured scope of the domains error
listener.

@shaunwarman
Copy link
Member

👍

After the response is finished, remove the request and
response objects from the domain and prevent them from
remaining in the captured scope of the domains error
listener.
@aheckmann
Copy link
Contributor Author

This is all set (I fixed the lint issues).

@grawk
Copy link
Member

grawk commented Dec 4, 2017

Looks like linting issues in the build.. ETA (must have been looking at a cached version of the page) .. Thanks @aheckmann

@aheckmann
Copy link
Contributor Author

you are correct, it was failing before but i forced pushed the fix :)

@bluelnkd
Copy link

bluelnkd commented Dec 4, 2017

👍 Neat... let me know when this gets published out... interested in getting this pulled into a future release.

@aheckmann
Copy link
Contributor Author

After a little more poking around, I found that the domains themselves are still being leaked (they hang around in the domain module's internal stack. I can kill that leak off too but it requires removing the domains code completely from this middleware. Domains were added in 7eafaef. Any arguments against removing them?

@xjamundx
Copy link
Contributor

xjamundx commented Dec 5, 2017

@aheckmann Excited to learn more about how you fixed this. We've been seeing a bad memory leak lately that we attributed to the stack issue, but possibly related to both. Great work.

Also, can you verify that your commit has your paypal email address and name properly set? It's not showing your icon.

@shaunwarman
Copy link
Member

Hmm definitely worth some due diligence. I know that domains are pending deprecation and the path forward isn't straight forward in core.

There are zones, experimental async-hooks and other help with async error handling approaches. All have trade-offs and issues.

It does look like this was added as a minor bump, but unsure who relies on it now for their error handling. And interested to know how shutdown was triggered before. Will need to take a peek at the code again.

@aheckmann
Copy link
Contributor Author

aheckmann commented Dec 5, 2017 via email

@aheckmann
Copy link
Contributor Author

aheckmann commented Dec 5, 2017

@xjamundx

Excited to learn more about how you fixed this. We've been seeing a bad memory leak lately that we attributed to the stack issue, but possibly related to both. Great work.

Long story short; it took about a week of reading / re-reading these fine articles:

Then a lot of experimentation + the heapdump module + finding a route which reproduced the memory leak (most of them did) + googling for domain related memory leaks.

The comparison view in Chrome Dev Tools told me that ServerResponses were being created but not gc'd. Once I had that, I checked to see if IncomingMessages were being leaked. When they were and Dev Tools showed domains involved, I used grep on node_modules to see what was using domains which was only our logging module and kraken. I first explored removing domains from the logging module but that didn't turn up any results. Then commented out krakens domain code which worked.

@xjamundx
Copy link
Contributor

xjamundx commented Dec 5, 2017 via email

@aheckmann
Copy link
Contributor Author

To keep things focused, I'll open an issue to continue the discussion for considering removal of domains.

This PR at least reduces the memory leak significantly and could be released as semver patch.

@aheckmann aheckmann changed the title Fix domain memory leak Partially fix domain memory leak Dec 5, 2017
@aheckmann aheckmann mentioned this pull request Dec 5, 2017
@aheckmann
Copy link
Contributor Author

A basic kraken app does not exhibit the leak. Therefore, I'm closing this PR because it isn't fixing the root cause (it just helps reduce the impact).

The cause of the leaking domains is due to an issue in another module, which once I patch, I'll link back here for future reference.

@aheckmann aheckmann closed this Dec 7, 2017
@aheckmann aheckmann deleted the fix_memory_leak branch December 22, 2017 00:08
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.

None yet

5 participants