9

I am using forever JS to run my node JS server continuously, however occasionally the server crashes and site goes down for some time.

I looked at the forever logs, and here it shows:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

<--- Last few GCs --->

35251732 ms: Mark-sweep 687.6 (219898.0) -> 687.6 (527360.0) MB, 13522.0 / 0 ms [allocation failure] [scavenge might not succeed].
35267178 ms: Mark-sweep 687.6 (527360.0) -> 687.6 (940128.0) MB, 15445.8 / 0 ms [allocation failure] [scavenge might not succeed].
35282842 ms: Mark-sweep 687.6 (940128.0) -> 687.6 (1352896.0) MB, 15664.3 / 0 ms [last resort gc].
35298326 ms: Mark-sweep 687.6 (1352896.0) -> 687.6 (1765664.0) MB, 15483.8 / 0 ms [last resort gc].


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x82f80fa5a91 <JS Object>
    2: decode(aka utf8decode) [/home/ubuntu/chat2/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-parser/node_modules/utf8/utf8.js:~200] [pc=0x19db242bd813] (this=0x1ea709fcc4c9 <an Object with map 0xedc29877b11>,byteString=0x1bd8952f0461 <Very long string[8570662]>)
    3: decodePacket [/home/ubuntu/chat2/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-...

error: Forever detected script was killed by signal: SIGABRT
error: Script restart attempt #9
Server running at http://localhost:1337/

Here are some more errors I found in my console.log file causing node to crash:

error: Forever detected script was killed by signal: SIGKILL
error: Script restart attempt #11


Error: read ECONNRESET
    at exports._errnoException (util.js:870:11)
    at TCP.onread (net.js:544:26)

RangeNotSatisfiableError: Range Not Satisfiable
    at SendStream.error (/home/ubuntu/chat2/node_modules/express/node_modules/connect/node_modules/serve-static/node_modules/send/index.js:245:31)
    at SendStream.send (/home/ubuntu/chat2/node_modules/express/node_modules/connect/node_modules/serve-static/node_modules/send/index.js:564:19)
    at onstat (/home/ubuntu/chat2/node_modules/express/node_modules/connect/node_modules/serve-static/node_modules/send/index.js:624:10)
    at FSReqWrap.oncomplete (fs.js:82:15)

Any idea on how to fix this? I can't seem to find the error ?

Faizan
  • 1,847
  • 8
  • 40
  • 63
  • I guess, you should look for memory leak – Alexey Ten May 29 '16 at 21:44
  • @AlexeyTen I have looked into memory leak, can you guide me how do I fix the memory leaks problems? I have added more error logs in my question, you may see. – Faizan May 30 '16 at 06:41
  • This link should good start https://www.google.com/search?q=nodejs+debug+memory+leak – Alexey Ten May 30 '16 at 09:06
  • sometimes nodejs was accidentially installed as 32bit version. i think there used to be a bug on the website, which always selected the 32bit version. at least i had this issue once... – denns Sep 22 '21 at 08:31

1 Answers1

10

You can try to increase the memory limit in node js using this,

node --max_old_space_size=8192 --optimize_for_size --max_executable_size=4096 --stack_size=4096

You can use it like this:

node --max_old_space_size=8192 --optimize_for_size --max_executable_size=4096 --stack_size=4096 yourfile.js

rahil sharma
  • 826
  • 7
  • 16
  • Which memory are we talking about here? Is the server in-memory used by Node JS during the app is running? Will it have any adverse affect on my hosting bills? My app is on AWS EC2. Can you please tell me do I have to run this command on terminal? because i am using forever to run my node app right now. is there any way to permanaentyl increase default memory? – Faizan May 29 '16 at 20:43
  • You can use it like this forever start -c "--max_old_space_size=8192 --optimize_for_size --max_executable_size=4096 --stack_size=4096 " yourfile.js – rahil sharma May 29 '16 at 20:48
  • I tried the exact same command as you said forever start -c "--max_old_space_size=8192 --optimize_for_size --max_executable_size=4096 --stack_size=4096 " index.js it gives message forever process running but my website is still down. However when I do it with forever start index.js it works. What is causing it not to work with the command parameters? plz help – Faizan May 30 '16 at 06:57
  • --optimize_for_size --max_executable_size=4096 --stack_size=4096 do not work with `node.js v14.1.0` – imsheth May 26 '21 at 07:02