Search code examples
node.jsangularangular-universalangular-ssr

Angular Universal application throwing "javascript heap out of memory" error in Docker container after running for a few days


I have an Angular application that has recently been converted to Angular Universal. The application is based on Angular 15 and is running inside a Docker container. The command used to initiate the server is "npm serve:ssr". The application runs fine for a day or two, but after that, it throws the error "ineffective mark-compacts near heap limit allocation failed - javascript heap out of memory".

To address this issue, I tried increasing the memory by adding the flag "max-old-space-size" to 3072. I modified the "serve:ssr" script in the package.json file to "node --max-old-space-size=3072 {project-name}/server/main.js". However, the problem still persists, causing my server to go down.

Here's the code snippet for the modified "serve:ssr" script in the package.json file

"scripts": {
  "serve:ssr": "node --max-old-space-size=3072 {project-name}/server/main.js"
},

Could you please help me understand why I'm still encountering this "out of memory" error despite increasing the memory allocation? Are there any additional steps or configurations I should consider to prevent this issue from occurring? Thank you in advance for your assistance.


Solution

  • This seems to be an issue with our code, I have fixed it by avoiding the memory leaks, by using strategies described in this link. https://stackoverflow.com/a/70527954/3493655