sails: Memory leak

Sails version:1.0.0-12 Node version:8.9.3 NPM version:5.5.1 DB adapter name: sails-mysql DB adapter version: 1.0.0-15 Operating system:na


https://github.com/node-machine/machine/issues/46

–Copied below:

screen shot 2017-12-16 at 2 35 10 pm

There is a memory leak in this module when called through sails-mysql. The above image shows the memory leak on a system with 768mb ram. The ECS container gets kicked when it reaches its max so that’s why the sawtooth. This is a low use system so this memory leak is quite significant. Reproduced locally with a fresh sails project and took heap snapshots before any calls and then after running many calls through the api. Compared these heaps in chromes profiling and found an alarming number of debug closures being left in memory(both snapshots were taken immediately after forcing a garbage collection)

screen shot 2017-12-15 at 11 03 00 am

This is easily reproducible by installing sails v1 and connecting it to a mysql db with some basic routes to add a record to the db.

Here is the code i used to get heap size and generate the snapshots:

npm install heapdump
const heapdump = require('heapdump');

 generateHeapDumpAndStats: function(req, res){
 //1. Force garbage collection every time this function is called
 try {
   global.gc();
 } catch (e) {
   console.log("You must run program with 'node --expose-gc index.js' or 'npm start'");
   process.exit();
 }

 //2. Output Heap stats
 var heapUsed = process.memoryUsage().heapUsed;
 console.log("Program is using " + heapUsed + " bytes of Heap.")
    res.status(200).json({heapUsed:heapUsed/1042/1024});

 //3. Get Heap dump
 //process.kill(process.pid, 'SIGUSR2');
    heapdump.writeSnapshot();
   }

These lines seem to be the culprit:

https://github.com/node-machine/machine/blob/13.0/lib/private/intercept-exit-callbacks.js#L260-L261 https://github.com/node-machine/machine/blob/13.0/lib/private/help-exec-machine-instance.js#L108-L110

I’m using the following versions:

    "sails": "^1.0.0-42",
    "sails-disk": "^1.0.0-12",
    "sails-hook-custom-blueprints": "^1.0.0",
    "sails-hook-grunt": "^3.0.0",
    "sails-hook-orm": "^2.0.0-22",
    "sails-mysql": "^1.0.0-15",

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 27 (15 by maintainers)

Commits related to this issue

Most upvoted comments

I can confirm that .sendNativeQuery does not work anymore with sails-mysql@1.0.0-16.

I’m running

    "sails": "^1.0.0-42",
    "sails-hook-grunt": "^3.0.2",
    "sails-hook-orm": "^2.0.0-22",
    "sails-postgresql": "^1.0.0-12",

in production, and the problem of loose instances of Debug not getting garbage collected is fixed.

@mikermcneil Thanks for fixing that. The debug() memory leak is gone! I ran through all my tests and everything looks good. Any timeline for getting this released?