Whenever I run a test on my IMAP Email Trigger, the test runs forever, and most of the time the server goes down, with this error:
Registered runner "JS Task Runner" (Hsdm0m9NjweG_oqZqNwgf)
<--- Last few GCs --->
[6:0x74d628357650] 85077 ms: Scavenge 1502.3 (1544.2) -> 1501.4 (1545.0) MB, 18.21 / 0.00 ms (average mu = 0.926, current mu = 0.732) allocation failure;
[6:0x74d628357650] 85104 ms: Scavenge 1503.0 (1545.0) -> 1502.6 (1555.2) MB, 10.40 / 0.00 ms (average mu = 0.926, current mu = 0.732) allocation failure;
[6:0x74d628357650] 85340 ms: Mark-Compact 1509.2 (1555.2) -> 1506.8 (1562.7) MB, 195.53 / 0.00 ms (average mu = 0.850, current mu = 0.493) allocation failure; scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
If I send an email to the email address with the workflow activated, nothing happensā¦
ā My email address is hosted by OVH, and the configuration seems to be OK as it is connected
What is the error message (if any)?
Please share your workflow
Share the output returned by the last node
I donāt have any output returned as the first step is not working, even in test
Information on your n8n setup
n8n version: 1.83.2
Database (default: SQLite): SQLite
n8n EXECUTIONS_PROCESS setting (default: own, main): main
Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
If you search this forum for JavaScript heap out of memory, youāll find plenty of threads covering this exact issue.
The problem is that some workflow on your instance is taking up so much memory that the node.js process runs out of memory.
You can address this by
looking at what workflow might be causing this, and either optimizing it, or disabling it, or
increasing the max available heap size by setting an env variable NODE_OPTIONS="--max-old-space-size=2048" to set the limit to 2GB
setting a concurrency limit by setting an env variable N8N_CONCURRENCY_PRODUCTION_LIMIT to something like 5 to make sure that at no point more than 5 concurrent executions are running
can you try setting it to NODE_OPTIONS="--max-old-space-size=6144" for 6GB, and see if that resolves the issue.
Itās not necessarily a great long-term solution, but it would help to know if the execution is taking a couple of GBs or memory, or if there is a bug thatās causing some kind of recursion and exhausting all memory.
Yes, Iāll try that.
The fact is that Iāve just installed n8n, I donāt have any workflow running.
Just a Gmail credentials, IMAP credentials, and one test-workflow
And the current usage is:
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
ddc08bad62b1 n8n 80.07% 1.082GiB / 3GiB 36.05% 3.06GB / 25.6MB 99.8MB / 340kB 20
It seems way too high for something doing nothing no?
And the usage is constantly changing:
root@srv746591:~/n8n-docker# docker stats n8n --no-stream
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
ddc08bad62b1 n8n 1.68% 2.501GiB / 3GiB 83.37% 4.47GB / 36.2MB 99.8MB / 344kB 20
root@srv746591:~/n8n-docker# docker stats n8n --no-stream
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
ddc08bad62b1 n8n 6.78% 2.506GiB / 3GiB 83.53% 4.47GB / 36.3MB 99.8MB / 344kB 20
thatās definitely way too high for an n8n instance doing nothing.
n8n usually starts up with around 350MB, but after 15 seconds or so, the usage should go down to 200-220MB.
No, not at all, Iāve just tried restarting the image, it doesnāt work
Well, Iāve followed the tutorial from hostinger: the one under āHow to install n8n on Ubuntu manually.-,How%20to%20install%20n8n%20on%20Ubuntu%20manually,-If%20you%E2%80%99re%20using)ā
Iāve installed it using containerized installation with docker
Should I remove everything and try the n8n tutorial?
Iāve already done it a few timeā¦
Thatās pretty weird, Iāve changed the config for a docker-compose.yml file
And now everything seems to be back to normal:
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
16297030b5b3 n8n 32.97% 206.3MiB / 3GiB 6.72% 329kB / 1.62MB 224MB / 221MB 20
With the CPU moving up and down though.
I donāt know what happened, itās really frustrating.
=> could that be the following: I had an IMAP trigger, which triggered for any email received and set to unread. It seems it went on the whole 7000 emails not read, and for each of them tried to mark as read etc.
I thought the trigger would only trigger when a new email arrives, not with the āoldā emails
I think the current implementation look for all āUNSEENā emails, and once all of those are processed, it saves the ālastMessageUidā, and for all future purposes always fetches emails after that ālastMessageUidā.
To avoid issues like this in the future, you could set the env variable N8N_CONCURRENCY_PRODUCTION_LIMIT to something like 10 to make sure that at no point there are more than 10 concurrent executions.
This should also help reduce the memory usage.
Makes sense, as youāve already mentioned earlier.
Thanks so much for your reply.
Iām closing the topic as Iāve successfully reach normal metrics.
For anyone seeing this topic lately, the only error was that too many unwanted actions were performed. Instead of just being triggered by new incoming emails, the event was triggered for my 6ā000 unread emails, which is too much.