sails: Memory leak even with homepage request!

I create a new sails project, add some lines into the default homepage view:

<script>
    setTimeout(function(window.location.reload();), 2000);
</script>

I make the page auto reload every 2 seconds, and this causes my VPS memory usage keep increasing until the VPS crash because out of memory. I can’t event ssh into the VPS and have to restart on cpanel.

Is this normal? If not, how can I fix this? Thanks

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 52 (20 by maintainers)

Most upvoted comments

To be clear, we still investigate every claim to the best of our ability-- but the community around Sails has grown to the point now that lately we find ourselves investigating potential memory leaks at least once per month, if not more often. And as @particlebanana pointed out, despite spending many hours diving in on numerous occasions, we just haven’t been able to replicate a leak (other than the Node v0.12-specific issue mentioned above). As you can imagine, it’s gotten to the point where it’s like the boy who cried wolf-- which isn’t good for anyone.

There are definitely situations where memory leaks can occur in Sails apps (happened to me more than I’d care to talk about)-- it’s just been my experience up until this point that those leaks come from either using non-production settings or from issues in app level code.

Something to keep in mind is that @particlebanana and I are running a couple of active apps on the latest stable version of Sails ourselves; thus we’re very aware of production issues in the latest stable version of Sails (i.e. if they arise, they hit us very close to home). If a memory leak was found in Sails or Waterline core w/ recommended production settings, we’d expect to find out about it pretty quickly. But since we can’t be 100% certain (because other adapters could be in play, Node version differences, etc) we have to check into this kind of thing every time.

So here’s what I’d ask from everyone going forward:

Before reporting a potential memory leak

  • If you run into a suspected memory leak, the first thing to do is check that you’re testing on an app using recommended production settings (see deployment/scalability docs on sailsjs.org.).
  • Next, check your app-level code (i.e. try to isolate the leak to a single endpoint). In my experience, it is very common w/ Node apps in general to end up with leaks from failing to handle errors (e.g. if you’re using promises and forget to do a .catch()).
  • If you can’t isolate the source of increasing memory usage to a particular endpoint or anything about your app code, then try replicating the leak in a brand new sails app running with no bells and whistles, with recommended production settings (see deployment docs on sailsjs.org). If you find an issue there, then please create an example repo that replicates the issue (and include the standard version info and instructions to reproduce).

Really appreciate the help! 🙇