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:
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)
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
- Update machine runner to v15. (refs https://github.com/balderdashy/sails/issues/4264) — committed to balderdashy/sails-mysql by mikermcneil 7 years ago
- Update machine runner to v15. (refs https://github.com/balderdashy/sails/issues/4264) — committed to sailshq/machinepack-mysql by mikermcneil 7 years ago
- Use mp-mysql@3 (see https://github.com/balderdashy/sails/issues/4264#issuecomment-353152823) — committed to balderdashy/sails-mysql by mikermcneil 7 years ago
- Merge commit 'f50689da650c8218301819c4f31703d9a658033b' * commit 'f50689da650c8218301819c4f31703d9a658033b': 3.0.1 Update eslint 3.0.0 Follow-up to d9d31aa1bec80d83e9b5b2383376740e68f9bc5e ... — committed to andrew-lyashenko/machinepack-mysql by andrii-liashenko 6 years ago
I can confirm that .sendNativeQuery does not work anymore with sails-mysql@1.0.0-16.
@bartbar this should be fixed as of https://github.com/balderdashy/sails-mysql/releases/tag/v1.0.0-17
I’m running
in production, and the problem of loose instances of
Debugnot 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?