Infinite loop

Hello!!!
I have a server with 1GB of RAM and there I deployed n8n with Docker. Every time I run a sequence of more than 10 rows in a csv, the sequence goes into an infinite loop at one of the nodes. Could you help me with this?


This is the flow

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        -1050,
        -160
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "document",
        "options": {}
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        -1050,
        140
      ],
      "webhookId": "1e471f09-c20e-4802-a562-b80b93a60d6e",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "options": {
          "readAsString": true
        }
      },
      "name": "Spreadsheet File3",
      "type": "n8n-nodes-base.spreadsheetFile",
      "typeVersion": 1,
      "position": [
        -660,
        140
      ],
      "alwaysOutputData": false,
      "retryOnFail": false,
      "notesInFlow": false
    },
    {
      "parameters": {
        "functionCode": "return Object.keys(items[0].binary).map(key => {\n  return {\n    json: {},\n    binary: {\n      data: items[0].binary[key],\n    }\n  }\n});\n\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        -860,
        140
      ]
    },
    {
      "parameters": {
        "url": "={{$node[\"SplitInBatches\"].json[\"Company Website\"]}}",
        "responseFormat": "string",
        "options": {
          "followRedirect": true
        },
        "headerParametersUi": {
          "parameter": [
            {
              "name": "User-Agent",
              "value": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.115 Safari/537.36"
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        -210,
        140
      ],
      "continueOnFail": true
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "name": "SplitInBatches",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        -420,
        140
      ]
    },
    {
      "parameters": {
        "functionCode": "// Loop over inputs and add a new field called 'myNewField' to the JSON of each one\nfor (item of items) {\n  const text = items[0].json.text.toLowerCase();\n  let found = false;   \n  let keyword = items[0].json.keyword;\n  for(let i = 0; i < keyword.length; i++) {\n        found = text.includes(keyword[i]);\n   if (found) { break; }\n          item.json.keywordFound = found\n    }\n  return items;\n}\n"
      },
      "name": "check for keyword",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        710,
        350
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"HTTP Request\"].json[\"data\"]}}",
              "operation": "isEmpty"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -30,
        140
      ]
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        100,
        -70
      ]
    },
    {
      "parameters": {},
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        960,
        330
      ]
    },
    {
      "parameters": {
        "mode": "mergeByIndex"
      },
      "name": "Merge1",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        500,
        350
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "name": "Set4",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1150,
        330
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "keyword",
              "value": "={{$node[\"Webhook\"].json[\"query\"][\"keyword\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "getKeywords",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        -160,
        370
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "Website",
              "value": "={{$node[\"HTTP Request\"].parameter[\"url\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "getWebsite",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        420,
        20
      ]
    },
    {
      "parameters": {
        "extractionValues": {
          "values": [
            {
              "key": "text",
              "cssSelector": "body"
            }
          ]
        },
        "options": {}
      },
      "name": "extractText&Url",
      "type": "n8n-nodes-base.htmlExtract",
      "typeVersion": 1,
      "position": [
        280,
        140
      ],
      "notesInFlow": false
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Spreadsheet File3": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Spreadsheet File3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SplitInBatches": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          },
          {
            "node": "getKeywords",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "check for keyword": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "extractText&Url",
            "type": "main",
            "index": 0
          },
          {
            "node": "getWebsite",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "NoOp": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          },
          {
            "node": "Set4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge1": {
      "main": [
        [
          {
            "node": "check for keyword",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "getKeywords": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "getWebsite": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "extractText&Url": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

By looking at your screenshot. The link back to Right End Merge node (with Append Label) to SplitInBatches is causing the loop.

Means, Once it hits the merge it’s looping back again and again

What exactly you’re trying to achieve?

2 Likes

I’m trying to see if there are words within a website and return an answer of whether these words are there or not.

You might have to add some sort of check that breaks the loop. You can check if the $runIndex equals the length of items returned by the Spreadsheet File node and break the loop if it >= the length.

1 Like

It’s curious! I already tried to do that, apparently it is a problem in the HTTP request node.
I’m still reading the documentation to see if it’s something I’ve overlooked.
Thanks

1 Like

Hey @rogelio94,

Did you solve the issue?
I found this example workflow that might be helpful: https://n8n.io/workflows/995

Thanks, great job :vulcan_salute:

1 Like