Search code examples
node.jsheroku

app/.heroku/node/bin/node taking up a lot of memory and crashing


Recently my heroku application started getting memory errors. I haven't really changed anything that may affect it. After some soak tests and debuggings, I noticed there are two node processes running on the dyno:

here is an example of what I see from a ps command:

~ $ ps aux | grep "node"
u18923      46  0.0  0.0   2616   612 ?        S    17:54   0:00 sh -c node ${NODE_INSPECT_FLAG} --gc-interval=100 --max-old-space-size=460 build-server/server/index.js
u18923      47  0.6  0.1 982148 79796 ?        Sl   17:54   0:03 node --gc-interval=100 --max-old-space-size=460 build-server/server/index.js
u18923      72 12.9  0.3 1079028 195700 ?      Sl   17:54   1:02 /app/.heroku/node/bin/node --gc-interval=100 --max-old-space-size=460 /app/build-server/server/index.js

The /app/.heroku/node/bin/node memory consumption goes up and eventually causes the app to crash since the environment is limited to 512MB memory.

Why are there two node processes? Why is the one coming from /app/.heroku is taking up so much more memory and crashing eventually. How can I fix this situation?


Solution

  • This was happening because of using https://www.npmjs.com/package/throng with concurrency of 1. It does seem like there is some sort of memory leak on local as well, i was checking the "forker" (parent) process instead of the actual one that is growing.