Repeated Crashes - JavaScript heap out of memory

Describe the problem/error/question

N8N workflow keeps crashing and then restarting. Log says “FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory”. I have also increased the memory from 4GB to 8GB but no luck. Recent changes include addition of simple code block to mimic switch node behaviour. Screenshots attached. This behaviour is only for workflows running longer like 5 mins or more.

What is the error message (if any)?

Error Message in the Docker Logs: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

No error message in the workflow execution.

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Can’t share workflow because of characters limit here.

Share the output returned by the last node



Information on your n8n setup

  • n8n version: 1.60.
  • Database (default: SQLite): Default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): Default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: ubuntu

hello @VK1234

It is better to move that part into the sub-workflow. As this one will cause potential Out of Memory issue
image

Thank you @barn4k ! But if I move it to a different sub workflow, it will take same amount of memory there and eventually causing same issue isnt it? I want to quanitify this, I want to see exactly which node taking how much memory and how I can optimise it. Taking almost 8 gb of memory is not efficient just a for 5-10 mins of text only data. How can I enable detailed logging to see exact steps and thier memory utilization?

Also looks like it is not even utilizing full memory, somewhere around 2.2 GB it crashes while I have allocated 7.5 GB. Is there a default setting that control how much memory it will use? And can we do something give proper warning and stop at memory full instead to just crash? Please see recordings and screenshots.

Screen Recording showing how N8N crashes after 2.2 GB : Screen Recording 2024-10-01 at 10.49.10.mov - Google Drive

The advantage of using a subworkflow is that it’ll release the memory after completion, so this might actually help.

ok, but can you answer why it is taking so much memory and even if I have like 7.5 gb, why it is crashing at 2 gb? And where and how can I see detailed logging on this?

Hi @VK1234

You might have to give the Node.js process itself more memory

--max-old-space-size=SIZE 

See our documentation here - Memory-related errors | n8n Docs

For the logging, you can set up our metrics endpoint

Thank you @ria, I have given more memory to as you suggested. The problem of workflow crashing at 2 GB is now resolved as I have increased the size to 6 gb, however it keeps piling on the data, for few hours of uses it has already accumulated 4.5 gb, how can i clear this and what kind of data it holds? All the workflow and execution data I belive is stored in the database, then what is this data and how can I clear it on periodic basis?

to clear the data you’ll need to use the sub-workflow. n8n keeps the memory until the execution is not finished and as you have a wait node there that can be used infinite times, the memory won’t be released at all.

Actually, you should move only these nodes into the sub-workflow
image

In that case your parent workflow will hold only the output of the Code node.

It is also good practice to set a hard limit for the workflow to work. E.g. no more than 4 hours. You can set it in the workflow settings.

2 Likes

Thank you @barn4k, I am new to sub-workflows specially on loops, do you have any suggestions or tutorial on how to do this? and what are best practices.