FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

Node version is v0.11.13

Memory usage during crash according to sudo top not raises over 3%

Code that reproduces this error:

var request = require('request')
var nodedump = require('nodedump')

request.get("http://pubapi.cryptsy.com/api.php?method=marketdatav2",function(err,res)
{
    var data
    console.log( "Data received." );
    data = JSON.parse(res.body)
    console.log( "Data parsed."   );
    data = nodedump.dump(data)
    console.log( "Data dumped."   ); 
    console.log( data )
})

To check if that a recursion stack size problem I have ran next code with --stack-size=60000 parameter

var depth = 0;

(function recurse() {
    // log at every 500 calls
    (++depth % 500) || console.log(depth);
    recurse();
})();

and have got

264500 
Segmentation fault

Then I ran code which gives me FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory with the same --stack-size=60000 parameter and haven't got Segmentation fault.

So I conclude CALL_AND_RETRY_LAST has nothing common with the recursion stack size.

How could I solve this problem? I believe there is enough free memory on my computer to finish this task successfully.

There are similar questions on stackoverflow but none of this questions are about CALL_AND_RETRY_LAST that's why I created separate question.


If you have a look at the source: github/v8, it seems that you try to reserve a very big object.According to my experience it happens if you try to parse a huge JSON object, but when I try to parse your output with JSON and node0.11.13, it just works fine.

You don't need more --stack-size, you need more memory: --max_new_space_size and/or --max_old_space_size.

The only hint I can give you beside that is trying another JSON-parser and/or try to change the input format to JSON line instead of JSON only.


$ sudo npm i -g increase-memory-limit

Run from the root location of your project:

$ increase-memory-limit

This tool will append --max-old-space-size=4096 in all node calls inside your node_modules/.bin/* files.


Node.js version >= 8 - DEPRECATION NOTICE

Since NodeJs V8.0.0, it is possible to use the option --max-old-space-size. NODE_OPTIONS=options...

$ export NODE_OPTIONS=--max_old_space_size=4096

To solve this issue you need to run your application by increasing the memory limit by using the option --max_old_space_size. By default the memory limit of Node.js is 512 mb.

node --max_old_space_size=2000  server.js 

I found that max_new_space_size is not an option in node 4.1.1 and max_old_space_size alone did not solve my problem. I am adding the following to my shebang and the combination of these seems to work:

#!/usr/bin/env node --max_old_space_size=4096 --optimize_for_size --max_executable_size=4096 --stack_size=4096

[EDIT]: 4096 === 4GB of memory, if your device is low on memory you may want to choose a smaller amount.

[UPDATE]: Also discovered this error while running grunt which previously was run like so:

./node_modules/.bin/grunt

After updating the command to the following it stopped having memory errors:

node --max_old_space_size=2048 ./node_modules/.bin/grunt