sails: Memory Leak in sails-mongo

Waterline version:0.10.26 Node version:0.10.33 && 4.3.1 NPM version:1.4.28 Operating system:Windows 7 x64 && Ubuntu 14.04.3 LTS


Referencing #1319

https://github.com/rootinc/waterline-test

Steps to reproduce bug:

  1. Clone the Repo
  2. Run sails lift
  3. Put something in the DB by running this in the browser: http://localhost:1337/test/create?name=Hello
  4. Reload this link over and over and watch the memory leak: http://localhost:1337/testthis/<newId>

OR

  1. Make a vanilla sails app.
  2. Then run sails generate api Test
  3. In TestController, add route that looks like this:
    testGet:function(req,res)
    {
    var testId = req.param(‘testId’);
    Test.findOneById(testId).then(function(test){
    res.send(“Hi”);
    });
    }
    
  4. In Test.js (model), added property schema:true, and property called name that is required and a string.
  5. In route.js, added this 'get /testthis/:testId' : 'TestController.testGet'
  6. In models.js, uncomment migrate:'alter'
  7. Reboot the server running sails lift
  8. Put something in the DB by running this in the browser: http://localhost:1337/test/create?name=Hello
  9. Reload this link over and over and watch the memory leak: http://localhost:1337/testthis/<newId>

For the time being, I am invoking global.gc every 15 minutes to clean up some memory. That seems help, but I know that is not a permanent solution.

Any assistance on this would be great. Thanks!

About this issue

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

Commits related to this issue

Most upvoted comments

A few things to make sure you are paying attention to. The default session store is memory so without moving that to something like connect-redis the process will eat up more and more memory and not release it.

Running a test on:

  • node@4.2.2
  • sails@0.12.3
  • sails-mongo@0.12.0
  • connect-redis@3.0.2

I used the example project posted above and ab to send it millions of requests. Here are the graphs I got back and after running all the requests I manually ran the garbage collector and ended up with heap usage and rss usage lower than when I started the process.

There are more postings here and here. These screenshots are only from a 15 min block but over the course of a few hours they remain relatively stable. With a memory leak you would see a clear trend upwards and I just haven’t seen anything like that.

For this I would try re-creating it with a fresh Sails project making sure the NODE_ENV is set to production and the session and socket stores are setup for production use.

screen shot 2016-04-25 at 5 24 07 pm screen shot 2016-04-25 at 5 23 59 pm screen shot 2016-04-25 at 5 23 49 pm