FATAL ERROR: invalid array length Allocation failed - JavaScript heap out of memory

Hello Everyone,

My app (lot of traffic) is crashing and showing this error…
I’m using node.js + docker on Digital Ocean.

I research and found this:

I tried to run node --max-old-space-size=4096 app.js # Increase limit to 4GB (as my server memory) but it’s not recognizing this command on Wappler Web Server terminal…

any tip @patrick?

Best

You have to edit the Docker-compose file for your production target

command: node --max-old-space-size=4096 index.js

I’m a bit surprised a lot of traffic is causing that error :slight_smile: Thought one would first hit a CPU bottleneck

Thanks @Apple!! Will give a try!! The CPU is hitting 2% of use…very weird!

Are you doing some endless loops or so? Fetching huge amount of data or a lot of huge image processing?

Normally it is really very difficult to run out of memory in NodeJS

There is a loop to add data into the database, but not endless…Maybe we have this loop working with many users at the same time and its is running out memory?

Maybe you can give us a sample of your loop?

Also you can monitor your NodeJS process when you run in local development and see on which actions the memory increase. You might need to run them multiple times to see the memory increase.

Hey @George! Thanks! Below, the loop:

For each loop, I generate a random number:

SELECT num as num_sorte_gerado FROM GENERATE_SERIES (100000, 999999) AS s(num) WHERE num not in (select num_sorte::INTEGER from cupom_sorte ) order by random() LIMIT 1

And then, insert into a table.

Well that doesn’t look like a problem to me.

So try to do some stress tests locally and investigate which action increases the memory of your NodeJS process.