memory leak in next 14.2.5
Unanswered
Purple Finch posted this in #help-forum
Purple FinchOP
We're observing the following memory pattern and are trying to see what can cause such memory leak in production.
The memory usage usually starts from <1GB and goes uptil 8GB when the k8s container is restarted.
Can someone help?
The memory usage usually starts from <1GB and goes uptil 8GB when the k8s container is restarted.
Can someone help?
26 Replies
Do you use next/image by any chances? I know of some reports where people pointed out next/image is the cause of memory leaks they are experiencing in self host
Also does this only start in 14.2.5 or already before that?
@Purple Finch Hey bro did you find any solution
Purple FinchOP
I found a few
1. recoil is leaking memory
2. react query is doing the same
3. next/image is also leaking memory
all these are server side leaks
do you happen to use any of this @Harish Garg 🥱
Giant panda
@Purple FinchHow do you know that the leak is coming from those libraries? Is it possible that the leak is caused by node.js or any other platform your app is running on?
Purple FinchOP
@Giant panda profiled in chrome dev tools memory tab
Giant panda
@Purple Finchso, it is client side?
Purple FinchOP
no you can run the chrome dev tools for a node process
Giant panda
then how about node gc works? is it release mem in a reasonable way?
Are you using ImageResponse by any chance? We just deleted it for its massive memory consumption and leaks.
Purple FinchOP
we just removed the next image optimizer in favor of cloudinary and it fixed it for us.
@Multiflora rose seed chalcid is something similar on the team's radar?
Transvaal lion
Same here, but it just stops at maximum and doesn't cause any performance degrading
Purple FinchOP
@Transvaal lion maximum what?
Transvaal lion
Request / limit of the pods
@Purple Finch <@712358149494931619> is something similar on the team's radar?
Dont tag people not present in the conversation.
Post an issue on github if you would like to report a bug.
There is an open issue for this opened by Tim.
Purple FinchOP
Ack
Hello! The issue that most people consider to be a leak is actually an accumulation of the file system cache in Linux.
If you examine the Nextjs caching algorithm in detail, you will see that it does not remove files that have already "expired" based on the expiredAt value. The Linux operating system, to optimize file access, tries to keep metadata (inodes) in RAM.
We observe this behavior because most often our application is deployed in an isolated container in a production environment on a cluster with large memory resources, and there are no parallel processes putting pressure on the RAM; as a result, the memory tries to fill up until it starts affecting performance.
I have created a script that automatically cleans up some of the cache files—you can give it a try.
Link: https://github.com/VadimOnix/next-image-cache-cleaner
If this helps you, I would be grateful for your star on my repository ✌️
If you examine the Nextjs caching algorithm in detail, you will see that it does not remove files that have already "expired" based on the expiredAt value. The Linux operating system, to optimize file access, tries to keep metadata (inodes) in RAM.
We observe this behavior because most often our application is deployed in an isolated container in a production environment on a cluster with large memory resources, and there are no parallel processes putting pressure on the RAM; as a result, the memory tries to fill up until it starts affecting performance.
I have created a script that automatically cleans up some of the cache files—you can give it a try.
Link: https://github.com/VadimOnix/next-image-cache-cleaner
If this helps you, I would be grateful for your star on my repository ✌️