Workflow not terminating when code node returns no output

Hello,

it often happens, though not always, that my workflow keeps running indefinitely after the code node returned no data. In these cases, the timeout of one minute is also ignored. After cancelling the execution everything looks fine though and there is no indication of why it did not stop:


Any ideas what could cause this?

Information on my n8n setup

  • n8n version: 1.6.1
  • Database (default: SQLite): PostgreSQL 15
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default/no change
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Azure WebApp Servides

Hi @jakob-cf :wave: Welcome to the community :tada:

There may be an issue with the code that you’re trying to run :thinking: Is this the only workflow that has this behaviour?

Could you share your workflow with us by hitting ctrl/cmd + a and then ctrl/cmd + c in the workflow editor, and then copying your workflow between two sets of three backticks (```)? If you follow those instructions, you won’t need to worry about accidentally sharing a token :+1:

Given though that this looks like there’s possibly a few nodes that are behind a login in this case, it might be best to give us a sample of what your incoming JSON data to the code node looks like, which we then can test more directly with your code.

Hi @EmeraldHerald ,

I cannot share the exact workflow because it contains credentials (unfortunately n8n credentials cannot be used in this case AFAIK) and other information. But I have created a very simple workflow to reproduce the issue.

  "meta": {
    "instanceId": "b2f0e2a5835ca49104389efacfec0a45894ab82d4f5ddb42145915d42205fefc"
  },
  "nodes": [
    {
      "parameters": {
        "jsCode": "return [];"
      },
      "id": "7d5e093f-cc8f-48da-9743-eea9fdd38e8c",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1780,
        320
      ],
      "executeOnce": true
    },
    {
      "parameters": {
        "mode": "combine",
        "combinationMode": "mergeByPosition",
        "options": {}
      },
      "id": "69b15212-20e3-410b-a660-d00e329349d3",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2.1,
      "position": [
        2360,
        320
      ]
    },
    {
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n  item.json.myNewField = 1;\n}\n\nreturn $input.all();"
      },
      "id": "2b92d211-3bbf-47c9-aed1-3e0df69aef3c",
      "name": "Code1",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2060,
        520
      ]
    },
    {
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n  item.json.myNewField = 1;\n}\n\nreturn $input.all();"
      },
      "id": "55a86f13-26e3-4f6c-9037-8c9fe229927d",
      "name": "Code2",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2580,
        320
      ]
    },
    {
      "parameters": {},
      "id": "460da579-07f2-4497-98f2-5dd8b5dbdc27",
      "name": "When clicking \"Execute Workflow\"",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        1520,
        320
      ]
    }
  ],
  "connections": {
    "Code": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          },
          {
            "node": "Code1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Code2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code1": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "When clicking \"Execute Workflow\"": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Now just executing this workflow manually a couple of times will always show " Workflow executed successfully" in the bottom right. But when I look at the executions they appear to be still running (except maybe the first one):


I hope this helps.
Btw. this is v1.7.1 now.

Hi @jakob-cf , thanks for that!

When your workflow ends because there’s no more data the execution should no longer show up as “running”. That being said, there is another aspect to this - if your example is returning an empty array and you’re not using “always output data”, then the workflow will continue to not output data :sweat_smile: You can change that here after clicking on the cogwheel setting menu of any node:

So that would be why the execution is stopping on the first node, in the example you provided.

However, when using your test workflow, the flow is ending just fine on my end:

It’s possible your instance is crashing when you’re running the real flow or even a node with no timeout handling, and thus you’re ending up with false executions data. Could you show us a real example scenario that shows the actual error you’re seeing? Obviously please redact anything sensitive :bowing_man: Otherwise this will be difficult to diagnose, I’m afraid.