n8n icon indicating copy to clipboard operation
n8n copied to clipboard

N8N crashes when processing a large number of items

Open valentina98 opened this issue 1 year ago • 4 comments

Describe the bug

When processing a large number of items, n8n crashes.

To Reproduce

  1. Add the following workflow:
{
  "name": "Test Error",
  "nodes": [
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "return item;"
      },
      "id": "820f3eed-3572-49c8-b8c0-c28ded1f152c",
      "name": "Return Item",
      "type": "n8n-nodes-base.code",
      "position": [
        620,
        240
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "39 * * * *"
            }
          ]
        }
      },
      "id": "c8df5724-7994-4a36-b363-df3b5e832e60",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        180,
        240
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "jsCode": "let data = [];\n\nfor(let i = 0; i < 7000; i++) {\n  let creation_time = \"2023-10-07T00:00:00+0000\";\n  data.push({creation_time})\n}\n\nreturn data;"
      },
      "id": "f7e308e5-19cf-4964-bbf5-c539e27a6c7d",
      "name": "Code Node",
      "type": "n8n-nodes-base.code",
      "position": [
        400,
        240
      ],
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Code Node",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code Node": {
      "main": [
        [
          {
            "node": "Return Item",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "7e52a50e-ac05-4b33-a5a6-3e0bdaaa2f44",
  "id": "d7ER3Kwvp2tdZTm6",
  "meta": {
    "instanceId": "43535d0062defd370fa413253c04340ec7fb74c5711be81c5375e75983283907"
  },
  "tags": []
}
  1. Adjust the Schedule Trigger (currently, it executes every hour at the 39-th minute)
  2. Activate the workflow and wait until it gets executed
  3. Refresh the page and observe that the user interface is not responding. At some point, n8n might fail with the following error:

ERROR: Execution stopped at this node n8n may have run out of memory while executing it. More context and tips on how to avoid this in the docs

Note: If the workflow does not fail on your machine, increase the number of items. If it takes too long to fail, restart n8n and navigate to the execution to see the error.

Expected behavior

If n8n runs out of memory, we expect the execution to fail without crashing n8n.

Environment:

  • OS: Ubuntu Linux 22.04
  • n8n Version: v1.8.2
  • Node.js Version: v18.17.0
  • Database system: default
  • Operation mode: main

Additional context

We believe we've encountered the same error in older versions of n8n with the following error messages:

  • job stalled more than maxStalledCount
  • Cannot read properties of undefined

valentina98 avatar Oct 09 '23 22:10 valentina98

Hey @valentina98,

Can you share the log output from n8n? This will tell us if it is running out of memory or if there is something else.

If n8n is running out of memory you could look at using queue mode to help scale across multiple servers without impacting the main n8n process or rework the flows to use smaller datasets.

Joffcom avatar Oct 10 '23 05:10 Joffcom

The issue here is that Code node has to create a sandbox for each input item. so, in the second code node you end up creating thousands of JS VMs, which is very expensive on memory and CPU. The Code node is currently not designed to handle such high number of input items, but we're looking into fixing that.

netroy avatar Oct 10 '23 10:10 netroy

it is not the code node. I got this issue on 1.21.1, 1.22.1 1.22.6 without any code node and again, the n8n production instance is down with hours of troubleshooting and even downgrading and doubeling the ressources was no solution.

I wonder why about 2 years ago I could run workflows 10 times the size of what I split them into now, without any problems?

prononext avatar Jan 17 '24 02:01 prononext

Hey @prononext

Can you share a workflow that doesn't work with larger datasets and the log output for when it crashes?

Most of the time it is down to a code node being used but if there is another node causing issues we will need more details to track down what is happening to fix it.

You mentioned it starts with 1.21.1 was that just an example or was say 1.20.0 working ok?

Joffcom avatar Jan 17 '24 04:01 Joffcom