Workflow freezes after several loop iterations (possible memory accumulation)

Describe the problem/error/question

I have a workflow that loops through a list of facilities.
For each facility, I call an API that returns invoices in pages of 10 items.
I split these 10 items, process each one, aggregate again, and send a POST.
Then I move to the next page and repeat.

Everything works for the first 6–7 loop iterations.
After that, the workflow freezes at the node right after the aggregate node and never continues.

What could be causing this?
Am I accumulating data or memory somewhere without noticing?
How can I release or clear data between iterations so the workflow doesn’t get stuck?


What is the error message (if any)?

There is no error message — the execution just freezes on one node and stays there indefinitely.

Information on your n8n setup

n8n version:
(enter your version here, e.g., 1.120.3)

When does it exactly freeze? Share the input and ouput of the node where/when it freezes.

It’s freezing at PREPARE_POST:

Your aggregate node is likely accumulating all items from every loop iteration, causing memory to grow until the workflow stalls (loop not release memory, you load all available records and keep this till workflow finish). The cleanest fix is to use sub-workflows: your main workflow loops through facilities and calls an Execute Workflow node for each one, which processes that facility’s invoices and returns only a summary. This way each iteration’s data gets released instead of piling up in memory.

1 Like

I tried ways to “clear the node cache”, but without success; I only solved my problem with the sub-workflow.

Thank you for your great help.

The node is freezing because there’s an undeclared variable (hasNext without let or const) which can cause a memory leak, and the node reference syntax is incorrect—you’re using .item.json instead of .first().json when referencing named nodes. Try adding const before hasNext and changing $('CALL_PARAMETER').item.json to $('CALL_PARAMETER').first().json throughout the code.

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