-
-
Notifications
You must be signed in to change notification settings - Fork 677
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
using class-validator in any file causes a memory leak #580
Comments
I believe that the root of the issue is the same for both TypeGraphQL and And it works fine, until you try to run it in an environment like lambda and when you try to build the schema on every request. As stated in many issues in this repo, you should build the schema only once and put into |
@MichalLytek Thanks for getting back. A few observations related to that.
We have added this to get rid of duplicates warning on subsequent requests. And yes you are right, we see the globals getting more and more of the compiled code strings, but that does not get stuck in the memory and GC is able to clean that up.
|
Based on the code: Every decorator call (another require) results in pushing to the big array, so this results in memory leaks as it store the metadata for classes that are not used anymore. Maybe you need to raise and issue on |
I think you should change the way how your code is called, otherwise it's just dirty patching, not fixing the root cause. |
Unfortunately, I don't think there is a way to have this working on the local correctly. Note that we don't need to do that on real deployed apps. |
Please decide 😄 So the leak is happening on real apps too but does not crash the machine as on local env? |
Haven’t you noticed the part about aws lambdas? |
@gevorggalstyan You're report is unclear and you're not helping with not answering to questions. Closing this issue as it looks like a TypeGraphQL metadata storage will be redesigned to use |
Describe the bug
importing anything from "class-validator" anywhere in the code causes memory leaks and eventually, the GC heaps crash. More specifically we are using typegraphql in a serverless stack and we have noticed that our local environment crashes with no reason with a GC heap overload. After some debugging and memory snapshots comparison we have figured out that whenever we use anything from the "class-validator" we have a memory leak. The memory consumption grows by a couple of MBs on each request and eventually, it crashes.
To Reproduce
Just bootstrap a minimal "apollo-server-lambda" serverless app, create a simple input type with a field validator and use apache benchmark to bombard the server. For a quicker result start the serverless with NODE_OPTIONS='--max-old-space-size=512', otherwise on 64bit systems it is 1400MB and it takes a while to crash it. You can even see how memory consumption grows while making requests. The code below is enough to reproduce the bug.
and here is the simple command to accelerate the repro
Expected behavior
Memory should stay clear and have no leaks and the application should not crash.
Logs
Enviorment (please complete the following information):
Additional context
This behavior has been observed on node versions from 10-12. we did not test on other versions.
The text was updated successfully, but these errors were encountered: