FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed

I have an app that connects a testing server (offline) to about 100 clients connected to it (Connected via LAN localhost:3000)

Sometimes, I get this error on my console and the app crashes

METEOR FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed 
JavaScript heap out of memory => Exited with code: 3

I have monitored RAM usage when it’s working with no issues, it sits around 200-800 MBs, but when the server reloads and I get the error above, it pushes RAM usage to about 1.5GB before it crashes displaying the error above and restarts and does it all over again.

I have increased the RAM allowance to 4GB by adding--max_old_space_size=4096 Then to 8 and even to 16GB, whatever the limit is, the usage keeps increasing to it until it crashes. Also, my Meteor is updated to the latest version (1.6.1)

The only way to get it back up is to disconnect all clients and reconnect them. Which indicates, one of the clients is causing a Memory Leak (Frozen connection or similar).

In terms of Meteor and NodeJS, as I’m a bit new, what are the best ways to deal with leaks or deal with this?

I appreciate the time taken to help.

1 Like

Maybe it’s a problem with subscriptions?

  • Could be that you didn’t set a limit on some publish function so it is publishing gazillions of documents
  • Could be that you subscribed but didn’t unsubscribe on a given page. So every time users navigate to that page, it adds one to the subscription count. This would be kind of like a memory leak, only a subscription leak. There is some code on stackoverflow that shows you how to count active subscriptions.

Just some thoughts, I hope you can fix it!

I haven’t used publish/subscribe in my code, could that be the issue? trying to send collections to multiple clients (Huge objects) and causing that particular client to crash?

And why does it only happen sometimes? Not regularly. After I restart all clients, it works fine, but when I play around with the code, and the server refreshes, sometimes it crashes, sometimes it doesn’t

Well if you don’t use pub/sub, that’s a good thing for performance.

I can’t tell from what you wrote, are you trying to send huge objects via meteor methods? If so, how big are they?

I don’t think sending big objects would be the issue though. In my experience something like this happens because you are forgetting to free variables once you have created them, maybe due to an infinite loop or something.

You could try hooking meteor up to the chrome developer tools. It takes a bit to set up, but Chrome has really nice tools for isolating memory leaks.

1 Like

I will definitely look into integrating chrome dev tools and see.

One more thing I noticed when my app crashes; when it happens, clients (that I assume the reason for memory leaks) do not refresh, they are stuck on whatever was happening before the crash, I need to turn them off before I can re-run the server.

My app is a timetable app that shows relevant details of, lets say, a bus. Clients are just browsers that show a certain URL, not really user-oriented.

ok to get chrome dev tools running is easier than I thought. Just this:

meteor run --inspect

Then you can debug client side like normal in chrome tools.
You can easily debug the server side part by clicking the green Node.js icon in the chrome developer tools on the client side page
node-dev-tools

1 Like

That is fantastic! I just tried it and it looks awesome. When I encounter the error again, I will use this method and reply back here with results.

Thanks “heaps” for your time :smiley:

Lol!

I hope you figure out what is causing the bug.