n8n icon indicating copy to clipboard operation
n8n copied to clipboard

[bug] Error workflow fails with "Cannot read properties of undefined (reading 'add')" in Queue Mode

Open JavierCane opened this issue 11 months ago • 1 comments

Bug Description

Hi!

💡 This issue could be related with this other one https://github.com/n8n-io/n8n/pull/14366 which was addressed in https://github.com/n8n-io/n8n/pull/14381.

In a Docker Swarm setup running n8n in queue mode (EXECUTIONS_MODE=queue), the error handler workflow fails to execute upon workflow errors. The following error is observed:

TypeError: Cannot read properties of undefined (reading 'add')
    at ScalingService.addJob (/usr/local/lib/node_modules/n8n/dist/scaling/scaling.service.js:184:38)
    at WorkflowRunner.enqueueExecution (/usr/local/lib/node_modules/n8n/dist/workflow-runner.js:257:45)
    at WorkflowRunner.run (/usr/local/lib/node_modules/n8n/dist/workflow-runner.js:141:24)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at WorkflowExecutionService.executeErrorWorkflow (/usr/local/lib/node_modules/n8n/dist/workflows/workflow-execution.service.js:278:13)

This issue arises when the error handler workflow is triggered due to an error in another workflow. 

Image

Click to expand the error handler workflow JSON
{
  "nodes": [
    {
      "parameters": {},
      "name": "Error Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        -660,
        -100
      ],
      "id": "16c5881e-1c3b-4d73-b9f1-3b29facba999"
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "=#notis-errors",
          "mode": "name"
        },
        "text": "={{ $json.errorsPrefix }} Error {{ $('Params').item.json.notificationLink }} → Node `{{ $('Params').item.json.execution.lastNodeExecuted ?? \"Unknown\"}}`:\n\n```\n{{ $('Params').item.json.execution.errorMessage }}\n```",
        "otherOptions": {
          "includeLinkToWorkflow": false
        }
      },
      "id": "016686e9-e35e-4fd6-96c3-60fa01916004",
      "name": "Send to Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.1,
      "position": [
        -220,
        -100
      ],
      "webhookId": "e702d8f3-c0b7-44eb-8b15-99114bad154e",
      "credentials": {
        "slackApi": {
          "id": "23",
          "name": "Slack notis-errors n8n"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "4554ddd8-7908-4cbd-8681-b347a58b0b05",
              "name": "workflow.name",
              "value": "={{ $json.workflow.name }}",
              "type": "string"
            },
            {
              "id": "d463eaee-5418-42d6-a4bf-320f6957173f",
              "name": "workflow.id",
              "value": "={{ $json.workflow.id }}",
              "type": "string"
            },
            {
              "id": "71426414-8dbe-4f86-818f-3c8a98d37463",
              "name": "execution.url",
              "value": "={{ $json.execution.url }}",
              "type": "string"
            },
            {
              "id": "dca8b2f7-e9bc-4472-85c2-6a68bfb7909e",
              "name": "execution.lastNodeExecuted",
              "value": "={{ $json.execution.lastNodeExecuted }}",
              "type": "string"
            },
            {
              "id": "65775f4a-580a-4b64-8f18-44783c75a985",
              "name": "execution.errorMessage",
              "value": "={{ $json.execution?.error.message ?? $json.trigger.error.message }}",
              "type": "string"
            },
            {
              "id": "bd0e5a0b-81e1-4a74-9951-508eae58ce10",
              "name": "notificationLink",
              "value": "={{ $json.execution?.url \n  ? `<${$json.execution.url}|executing the workflow \\`${$json.workflow.name}\\`>` \n  : `executing <https://${$env.N8N_HOST}/workflow/${$json.workflow.id}|the workflow \\`${$json.workflow.name}\\`>` \n}}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -440,
        -100
      ],
      "id": "5bee1f6b-a8d5-4649-84c3-ba0ec08416ec",
      "name": "Params"
    }
  ],
  "connections": {
    "Error Trigger": {
      "main": [
        [
          {
            "node": "Params",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Params": {
      "main": [
        [
          {
            "node": "Send to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Additional context:

The issue seems related to the ScalingService.addJob method, where it attempts to access the add property of an undefined object. This might be due to the error handler workflow not being properly enqueued in queue mode.

The failed executions due to this error also seems to contain some data inconsistencies based on the started timestamp and durations shown in the execution list:

Image

Feel free to ask for any other context if I can help you out debugging the issue 😇

Thanks!

To Reproduce

  1. Set up n8n with EXECUTIONS_MODE=queue, a main node, and multiple worker nodes.
  2. Configure an error handler workflow using the Error Trigger node.
  3. Induce an error in another workflow to trigger the error handler.
  4. Observe the error in the logs. 

Expected behavior

The error handler workflow executes successfully upon being triggered by an error in another workflow.

Operating System

Ubuntu

n8n Version

1.91.3

Node.js Version

20.19.0

Database

PostgreSQL

Execution mode

queue

JavierCane avatar May 08 '25 18:05 JavierCane

Hey @JavierCane,

We have created an internal ticket to look into this which we will be tracking as "GHC-1912"

Joffcom avatar May 08 '25 18:05 Joffcom

I'm experiencing the same thing @Joffcom @ivov Any progress on this issue please?

checkblue avatar Jun 08 '25 15:06 checkblue

@JavierCane, has this problem ever arisen again?

checkblue avatar Jun 08 '25 15:06 checkblue

Nope @checkblue, it seems to be solved 🙌

I have upgraded to 1.98.2, which includes the fix deployed in 1.98.0 from the PR mentioning this issue (#16098), and the Executions page does not contain any errors like the ones shown in the issue description 🎉

JavierCane avatar Jun 23 '25 11:06 JavierCane