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.

Hi @EmeraldHerald,
then I am probably just doing it wrong. I don’t want the workflow to continue at all. That’s why I output an empty array. What is the correct way to abort my workflow from a code node?

HI @jakob-cf :wave: If you return an empty array, then n8n should stop executing the workflow if a node has no output data. I’m really sorry for the misunderstanding, and I’ve tried your workflow several times - I’m not too sure why you’re seeing these executions run endlessly, but I’m not reproducing this even running the workflow approximately 20 times, they all finished as appropriate :see_no_evil: Can you emulate the behaviour with other HTTP services (such as webhook.site)?

1 Like

Hi @EmeraldHerald,

the issue does not occur anymore now. We have updated the version several times since then and apparently the timezone configuration which was missing/incorrect was also fixed according to our IT who manage the installation.
So I guess either one of those changes fixed the issue.
Thanks for your support.

I have something similar occurring in a couple of my flows, but it seems to be only on production calls. Mine is in the cloud version 1.20. The flow get to the last node and then runs indefinitely. I have to cancel the flow else it continues to have a status of running, but then I can open up the flow and see it ran the last node, for me its the “Do Nothing” node. It never happens when do test calls to the flow. Still not sure what’s causing it.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.