-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Memory leak (Help wanted) #9259
Comments
@vkarpov15 I don't know where the leak is happening so I can't provide repro script , sorry. I can show you the full code of repo. Thanks |
I'll take a look and see what I can find from the information you included. If that isn't enough to repro this, I'll need to take a look at the full repo. |
Thank you. |
@ktjd123 I took a closer look at your code samples and I don't think there's enough info for me to repro this. Can you post the changes you made that appear to fix the leak as well? Also, if you would be willing to give me access to your repo, that would be helpful. My email is val@karpov.io. |
I can probably look into this more, but my best explanation so far is this: Node.js doesn't forward errors when doing |
@vkarpov15 That might be a problem. I changed to singleton instance after thinking of that problem, and reduced pool size 1000 -> default. I saw several mongoose errors at server that file is not found. I added logic to check if file exists. -> I think this helps to manage memory but still having growth of memory so I think there is other problem I used pm2 to restart after nodejs uses memory after 2G and it has 305 restart records for uptime of 10d. Thank you for your help :)! |
Hi @vkarpov15 , I don't know if this is related or not. But we are getting memory leaks quite often. Below are the logs we have when the app crashes. Seems to be an issue with an embedded document.
We have mongoose version |
Seems like an infinite loop here https://github.com/Automattic/mongoose/blob/master/lib/types/embedded.js#L399 |
Turned out our problem above was caused by a memory leak issue in |
I did some more digging, but haven't been able to find any more insights other than the Re: @buccfer 's comment here, we'll add an extra check to throw if there's an infinite loop in that case. While I don't see how there could be an infinite loop here, it's best to be defensive and throw an error if that does happen. |
…ment is a parent of itself in `ownerDocument()` Re: #9259
Do you want to request a feature or report a bug?
bug (help wanted)
What is the current behavior?
memory leak
If the current behavior is a bug, please provide the steps to reproduce.
memory grows over time. have no idea why
This happened after updating some code. the code seems to be totally fine.
Did to solve issue.
Didn't work.
Mongoose connection code.
gridfs bucket instance code.
file loading api.
heap snapshot comparison between start and now.
first one is about bson
and second ~~ most are about this and have no idea what this is about
server is Next.js based custom server with express.js.
Below is serverside code of the commit. It seems to be memory leak is happend after this commit.
addToPointArray is global variable and is
about 6k accounts, 1k pointdeposithistories, 6k pointhistories.
I know code is not properly optimized, but have no idea why there is memory leak..
I'm using pm2 clustered(2 clusters) mode for this.
when I see heap size through pm2 monit It only shows about 100mb ~ 200mb but when I see total memory usage through pm2 list, It grows forever (over 2GB).
Thank you and always appreciate your works.
What is the expected behavior?
no memory leak
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node.js v12.18.0
mongoose ^5.9.24
mongoDB mongod --version
db version v3.6.8
git version: 8e540c0b6db93ce994cc548f000900bdc740f80a
OpenSSL version: OpenSSL 1.1.1f 31 Mar 2020
allocator: tcmalloc
modules: none
build environment:
distarch: x86_64
target_arch: x86_64
The text was updated successfully, but these errors were encountered: