next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Memory leaks

Open HeadFox opened this issue 7 years ago • 11 comments

Bug report

Describe the bug

We have some problem on our server. After some time of execution we have an out of memory error on our 3Go AWS server. So I tried to log on my computer. I launch refresh of the home page every 5 seconds to see if the memory increase. Here is the memory evolution :

image image

Here is the statistics just after nextjs server was launch :

image

Statistics on last snpashot image

Any idea ? I don't know where to look for debugging this... Thanks !

System information

  • OS: macOS
  • Browser (if applies): Chrome
  • Version of Next.js: 10.13.0
  • NextJS: 8.0.0
  • react-apollo: 2.4.1
  • jss: 10.0.0-alpha.10

HeadFox avatar Feb 21 '19 13:02 HeadFox

Any idea ? I don't know where to look for debugging this...

It's pretty much impossible to say without having a reproduction.

timneutkens avatar Feb 21 '19 14:02 timneutkens

Try disabling JSS Not sure what you used, but some JSS implementations in app and document were leaky

Yzrsah avatar Feb 22 '19 07:02 Yzrsah

Maybe it comes from here : https://github.com/apollographql/react-apollo/issues/2126

When I looked into comparaison between snapshots, maybe it comes from apollo : image

HeadFox avatar Feb 22 '19 09:02 HeadFox

Maybe it is, please provide a full reproduction otherwise it'll still be hard to track down from our side 🙏

timneutkens avatar Mar 05 '19 16:03 timneutkens

@Yzrsah Hey you mentioned that JSS had some leaky implementations in app and document. I'm seeing a memory leak that might be related to JSS, do you have any info on what implementations were leaky? I'm using Material UI.

Irrelon avatar May 10 '19 16:05 Irrelon

Hi @Irrelon ! A lot of nextJs update since I posted this issue. I don't have any problem anymore but be sure to correctly implement Link component (with href and as) as it might cause some memory problems :)

HeadFox avatar May 10 '19 16:05 HeadFox

@HeadFox Thanks for the info :)

I actually think I've fixed it about an hour after posting... and it was because I'd very stupidly hooked an event listener in the constructor of a component and put the de-hook in componentWillUnmount which of course doesn't run server-side. After putting a if (process && process.browser) in the constructor code where it executes the event listener hook I have (I think) solved the problem.

Essentially:

  1. It was my fault
  2. Don't make event listeners that are cancelled in react lifecycle methods on the server-side :p

Irrelon avatar May 10 '19 17:05 Irrelon

We were facing memory leaks with a similar configuration as mentioned above and we identified the problem layed in our SSR configuration. After passing the ssrMode property in the ApolloClient config everything works fine.

see here: https://www.apollographql.com/docs/react/features/server-side-rendering/#server-initialization

himynameissebbo avatar Jul 04 '19 07:07 himynameissebbo

We have some problems with our server. After some time of execution, we have an out of memory error on the server. So I tried to log on to my computer. I launch the refresh of the Search page every 5 seconds to see if the memory increase. Here is the memory evolution : SAVE_20200512_152019

So the conclusion is the bigger the size of user bigger the memory usage ultimately it will slow down the application or affect application performance please provide a full reproduction

ebs-PriyankaKanwar avatar May 12 '20 10:05 ebs-PriyankaKanwar

Hi @Irrelon ! A lot of nextJs update since I posted this issue. I don't have any problem anymore but be sure to correctly implement Link component (with href and as) as it might cause some memory problems :)

Do you know why this would cause memory issues? On our next.js app we have a custom link button that utilizes the next.js Link component but we aren't using as with href or passHref. We're seeing a huge memory leak issue and this custom link component is our most widely used component.

Dnguye92 avatar Apr 26 '21 18:04 Dnguye92

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

balazsorban44 avatar Jan 28 '22 11:01 balazsorban44