FATAL ERROR: JS Allocation failed – process out of memory

We recently started seeing a spate of node processes dying with the unhelpful error:

FATAL ERROR: JS Allocation failed - process out of memory

Unfortunately, there’s no callstack provided. A StackOverflow answer suggested installing the OFE package, which got us a “heapdump” but it still wasn’t obvious what the problem was.

Eventually we spotted a pattern in the logs, and adding more logging led to a reproducible test case. It turned out that the bug was caused by using an array instead of an object (“hashmap”):

var foo = [];
foo[1000000001] = {};
console.log('got here');
console.log(foo);
console.log('boom!');

Accessing the array with a high id caused a huge array to be created, and trying to print that array caused the process to consume all the available memory.

UPDATE: we’re not the only ones to run into this issue.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s