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

Clean old context references #21

Open
jeremyvergnas opened this issue Mar 5, 2018 · 3 comments
Open

Clean old context references #21

jeremyvergnas opened this issue Mar 5, 2018 · 3 comments
Assignees

Comments

@jeremyvergnas
Copy link

Hi there,

I was wondering whether the Map of contexts would be automatically cleaned at some point or should we use destroy to do that?

It could lead to performance issue as the Map is becoming bigger and bigger.

Thanks for your work!

@Jeff-Lewis Jeff-Lewis self-assigned this Mar 18, 2018
@Jeff-Lewis
Copy link
Owner

@jeremyvergnas See #11 Memory leak in _contexts which discusses it. Contexts are removed on async_hook's destroy event, although it appears sometimes to take a while for some resources to be garbage collected.
That said, there was some additional work added in node 9.3.0 for destroy event in garbage collected AsyncResources, although I think the use of AsyncResources by embedder libs is small but hopefully growing.

@bripkens
Copy link

It should be noted that usage of an HTTP agent with maxSockets: Infinity, maxFreeSockets: 256 can also result in the same situation: A lot of sockets will be created which results in a lot of cls-hooked context objects. The socket objects will only start to get GCed at a later point.

This becomes especially problematic when adding (potentially) large objects to the CLS context.

In our specific case, we are adding additional cleanup logic on top of cls-hooked to reduce the impact and likeliness of problems.

@MingxuanLi
Copy link

I did a quick test with 100 concurrent HTTP requests for like a couple of minutes watching the memory usage, did not see any major leakage on the heap_used so far. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants