Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sails Memory Leak or Keep increasing #3099

Closed
shumailarshad opened this issue Jul 21, 2015 · 83 comments
Closed

Sails Memory Leak or Keep increasing #3099

shumailarshad opened this issue Jul 21, 2015 · 83 comments
Labels

Comments

@shumailarshad
Copy link

I have created a new sails js app and did not change any code in it.

Than I used pm2 to launch two instance of that app. Memory keep increasing without hitting app even once.

I have done the same with basic express.js app with following code but it does not increase memory

"
var express = require('express');
var app = express();

app.get('/', function (req, res) {
res.send('Hello World!');
});

var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;

console.log('Example app listening at http://%s:%s', host, port);
});
"

screenshot from 2015-07-21 14 01 13

@RWOverdijk
Copy link
Contributor

Interesting. Is it running migrations?

@shumailarshad
Copy link
Author

It is not doing anything. All I did is
sails new demo
cd demo
pm2 start app.js -i 2 --name "sailsApp"

And now it was increased further, I have not touched or used that app at all. Why the memory would increase.
screenshot from 2015-07-21 14 45 10

@shumailarshad
Copy link
Author

And memory has increased to:

screenshot from 2015-07-21 17 44 16

Without using it at all.

Can someone please help

@richdunajewski
Copy link

Approximately how long does it take for the memory to grow to that level? Are we talking minutes, hours, or days?

Does this only happen when in cluster mode? If not, what happens if you start by command line without pm2?

@shumailarshad
Copy link
Author

Above levels took about 2 - 3 hrs to grow but if you keep looking at it, you can see memory growing in MBs.

And following is the picture after leaving it overnight.

screenshot from 2015-07-22 09 11 44

I will test forked mode now to compare if I am getting same results or not.

And also will run it without pm2.

@RWOverdijk
Copy link
Contributor

@shumailarshad Thank you for going the extra mile! This is important information.

@shumailarshad
Copy link
Author

After testing fork mode for 3 hours, I found out that the problem is only cluster mode. It is some problem with sails js as express working with pm2 in cluster mode absolutely fine.

screenshot from 2015-07-22 11 55 11

@Josebaseba
Copy link
Contributor

Maybe the grunt hook gets crazy in cluster mode? Try to start the sails app in cluster mode disabling the grunt hook, in the .sailsrc file, and take a look.

@richdunajewski
Copy link

@Josebaseba read my mind, I was wondering the same thing. 👍

@shumailarshad
Copy link
Author

How to disable grunt hook. Can you please help? Or may be how to disable sails modules which I will not be using at all.

@Josebaseba
Copy link
Contributor

Change the .sailsrc file to:

{
  "hooks": {
    "grunt": false
  }
}

@shumailarshad
Copy link
Author

I have disabled grunt and tried again but it does not help.

screenshot from 2015-07-23 11 18 13

This is after running app for about an hour. Memory used keep increasing.

@Josebaseba
Copy link
Contributor

That's an important bug then, but I don't have any idea what could be the reason. It looks like an infinite loop, maybe we could have more info starting the app in silly or verbose log mode, and looking the logs.

@shumailarshad
Copy link
Author

Following are the logs when I run sails app with --silly and pm2 cluster mode. There has been some extra logging which might be the root cause. Can anyone please have a look at it.

sailsApp-out.0.log
"""""""""

�[36mverbose: �[39mSetting Node environment...
�[36mverbose: �[39mmoduleloader hook loaded successfully.
�[36mverbose: �[39mLoading app config...
�[36mverbose: �[39muserconfig hook loaded successfully.
�[36mverbose: �[39mExposing global variables... (you can disable this by modifying the properties in sails.config.globals)
�[36mverbose: �[39mLoading user hooks...
�[36mverbose: �[39muserhooks hook loaded successfully.
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Configured view engine, ejs
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: logger
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: request
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: orm
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: views
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: blueprints
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: responses
�[36mverbose: �[39mLoading runtime custom response definitions...
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: controllers
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: sockets
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: pubsub
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: policies
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: services
�[36mverbose: �[39mLoading app services...
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: csrf
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: cors
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: i18n
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: session
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: http
�[36mverbose: �[39mlogger hook loaded successfully.
�[36mverbose: �[39mrequest hook loaded successfully.
�[36mverbose: �[39mLoading the app's models and adapters...
�[36mverbose: �[39mLoading app models...
�[36mverbose: �[39mLoading app adapters...
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Building action for view: 403
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Building action for view: 404
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Building action for view: 500
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Building action for view: homepage
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Building action for view: layout
�[36mverbose: �[39mLoading blueprint middleware...
�[36mverbose: �[39mblueprints hook loaded successfully.
�[36mverbose: �[39mresponses hook loaded successfully.
�[36mverbose: �[39mcontrollers hook loaded successfully.
�[36mverbose: �[39mLoading policy modules from app...
�[36mverbose: �[39mFinished loading policy middleware logic.
�[36mverbose: �[39mpolicies hook loaded successfully.
�[36mverbose: �[39mservices hook loaded successfully.
�[36mverbose: �[39mcsrf hook loaded successfully.
�[36mverbose: �[39mcors hook loaded successfully.
�[36mverbose: �[39mi18n hook loaded successfully.
�[36mverbose: �[39msession hook loaded successfully.
�[36mverbose: �[39mhttp hook loaded successfully.
�[36mverbose: �[39mOverriding ejs engine config with ejslocals to implement layout support...
�[36mverbose: �[39mPreparing socket.io...
�[36mverbose: �[39msockets hook loaded successfully.
�[36mverbose: �[39mviews hook loaded successfully.
�[36mverbose: �[39mSetting default Express view engine to ejs...
�[36mverbose: �[39mStarting ORM...
�[36mverbose: �[39morm hook loaded successfully.
�[36mverbose: �[39mpubsub hook loaded successfully.
�[36mverbose: �[39mBuilt-in hooks are ready.
�[36mverbose: �[39mInstantiating registry...
�[36mverbose: �[39mLoading router...
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: all /* (REQUEST HOOK: addMixins)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: all /* (RESPONSES HOOK: addResponseMethods)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: all /* (I18N HOOK: addLocalizationMethod)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: all /* (VIEWS HOOK: addResViewMethod)
�[36mverbose: �[39mPolicy-controller bindings complete!
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: /* (CSRF HOOK: CSRF)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: all /* (CORS HOOK: clearHeaders)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: /csrfToken (CORS HOOK: sendHeaders)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: options /csrftoken (CORS HOOK: preflight)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: /csrfToken (FUNCTION: csrfToken)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: / (FUNCTION: rememberViewId)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: / (FUNCTION: serveView)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: get /**getcookie (SOCKETS HOOK)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: get /csrfToken (FUNCTION: csrfToken)
�[36mverbose: �[39mAll hooks were loaded successfully.
�[36mverbose: �[39mStarting app at /home/shumailarshad/nodeProjects/sailsApp...
�[36mverbose: �[39mRunning the setup logic in sails.config.bootstrap(cb)...
�[32minfo: �[39m
�[32minfo: �[39m .-..-.
�[32minfo: �[39m
�[32minfo: �[39m Sails <| .-..-.
�[32minfo: �[39m v0.12.0-rc3 |
�[32minfo: �[39m /|.
�[32minfo: �[39m / ||
�[32minfo: �[39m ,' |'
�[32minfo: �[39m .-'.-==|/_--'
�[32minfo: �[39m --'-------' �[32minfo: �[39m __---_**--**_---**_--**_---**_--___ �[32minfo: �[39m ____---**_--**_---**_--**_---**_--**_-__ �[32minfo: �[39m �[32minfo: �[39mServer lifted in /home/shumailarshad/nodeProjects/sailsApp�[32minfo: �[39mTo see your app, visit �[4mhttp://localhost:1337�[24m �[32minfo: �[39mTo shut down Sails, press <CTRL> + C at any time. �[37m�[39m �[37m�[39m �[36mverbose: �[39mCould not fetch session, since connecting socket has no cookie (is this a cross-origin socket?) Generated a one-time-use cookie:sails.sid=s%3AtUAU7KVTXHSmFFNdpXU1hBAEcoS_DAjt.A%2FO91d3L2bcP2UNEVLya4mHvZkfzR5BrNl96CxIjUYsand saved it on the socket handshake. This will start this socket off with an empty session, i.e. (req.session === {}) That "anonymous" section will only last until the socket is disconnected unless you persist the session id in your database, or by setting the set-cookie response header for an HTTP request that you _know_ came from the same user (etc) Alternatively, just make sure the socket sends acookieheader or query param when it initially connects. �[36mverbose: �[39mCould not fetch session, since connecting socket has no cookie (is this a cross-origin socket?) Generated a one-time-use cookie:sails.sid=s%3Aj8uL6A3dddjggkakIYr1ep3cF7y8xT_t.uP9syaNPMiQjI33hNNiKuNP9XM8Hkpsg1CriYoSC7Qgand saved it on the socket handshake. This will start this socket off with an empty session, i.e. (req.session === {}) That "anonymous" section will only last until the socket is disconnected unless you persist the session id in your database, or by setting the set-cookie response header for an HTTP request that you _know_ came from the same user (etc) Alternatively, just make sure the socket sends acookieheader or query param when it initially connects. �[36mverbose: �[39mCould not fetch session, since connecting socket has no cookie (is this a cross-origin socket?) Generated a one-time-use cookie:sails.sid=s%3AjeC-ps0Uf7HcBfie6rRFilDTGJUQhgfm.dMkoe%2FZe2NqJEvuqT0APaGDcS1xQF8QBbuw9xSjeVsMand saved it on the socket handshake. This will start this socket off with an empty session, i.e. (req.session === {}) That "anonymous" section will only last until the socket is disconnected unless you persist the session id in your database, or by setting the set-cookie response header for an HTTP request that you _know_ came from the same user (etc) Alternatively, just make sure the socket sends acookie` header or query param when it initially connects.
�[36mverbose: �[39mCould not fetch session, since connecting socket has no cookie (is this a cross-origin socket?)
Generated a one-time-use cookie:sails.sid=s%3Afn2dDhcvQQU2OFK3AlULSSrdED0shTzc.5Wumr9U%2FuHqT2uLj%2BvGHL1A1sEQdMjccFDcV5ASoeCYand saved it on the socket handshake.

""""""""""""""


sailsApp-out-1.log:
""""""""""""""

�[36mverbose: �[39mSetting Node environment...
�[36mverbose: �[39mmoduleloader hook loaded successfully.
�[36mverbose: �[39mLoading app config...
�[36mverbose: �[39muserconfig hook loaded successfully.
�[36mverbose: �[39mExposing global variables... (you can disable this by modifying the properties in sails.config.globals)
�[36mverbose: �[39mLoading user hooks...
�[36mverbose: �[39muserhooks hook loaded successfully.
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Configured view engine, ejs
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: logger
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: request
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: orm
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: views
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: blueprints
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: responses
�[36mverbose: �[39mLoading runtime custom response definitions...
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: controllers
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: sockets
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: pubsub
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: policies
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: services
�[36mverbose: �[39mLoading app services...
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: csrf
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: cors
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: i18n
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: session
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Loading hook: http
�[36mverbose: �[39mlogger hook loaded successfully.
�[36mverbose: �[39mrequest hook loaded successfully.
�[36mverbose: �[39mLoading the app's models and adapters...
�[36mverbose: �[39mLoading app models...
�[36mverbose: �[39mLoading app adapters...
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Building action for view: 403
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Building action for view: 404
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Building action for view: 500
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Building action for view: homepage
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Building action for view: layout
�[36mverbose: �[39mLoading blueprint middleware...
�[36mverbose: �[39mblueprints hook loaded successfully.
�[36mverbose: �[39mresponses hook loaded successfully.
�[36mverbose: �[39mcontrollers hook loaded successfully.
�[36mverbose: �[39mLoading policy modules from app...
�[36mverbose: �[39mFinished loading policy middleware logic.
�[36mverbose: �[39mpolicies hook loaded successfully.
�[36mverbose: �[39mservices hook loaded successfully.
�[36mverbose: �[39mcsrf hook loaded successfully.
�[36mverbose: �[39mcors hook loaded successfully.
�[36mverbose: �[39mi18n hook loaded successfully.
�[36mverbose: �[39msession hook loaded successfully.
�[36mverbose: �[39mhttp hook loaded successfully.
�[36mverbose: �[39mOverriding ejs engine config with ejslocals to implement layout support...
�[36mverbose: �[39mPreparing socket.io...
�[36mverbose: �[39msockets hook loaded successfully.
�[36mverbose: �[39mviews hook loaded successfully.
�[36mverbose: �[39mSetting default Express view engine to ejs...
�[36mverbose: �[39mStarting ORM...
�[36mverbose: �[39morm hook loaded successfully.
�[36mverbose: �[39mpubsub hook loaded successfully.
�[36mverbose: �[39mBuilt-in hooks are ready.
�[36mverbose: �[39mInstantiating registry...
�[36mverbose: �[39mLoading router...
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: all /* (REQUEST HOOK: addMixins)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: all /* (RESPONSES HOOK: addResponseMethods)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: all /* (I18N HOOK: addLocalizationMethod)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: all /* (VIEWS HOOK: addResViewMethod)
�[36mverbose: �[39mPolicy-controller bindings complete!
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: /* (CSRF HOOK: CSRF)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: all /* (CORS HOOK: clearHeaders)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: /csrfToken (CORS HOOK: sendHeaders)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: options /csrftoken (CORS HOOK: preflight)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: /csrfToken (FUNCTION: csrfToken)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: / (FUNCTION: rememberViewId)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: / (FUNCTION: serveView)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: get /**getcookie (SOCKETS HOOK)
�[31ms�[39m�[33mi�[39m�[32ml�[39m�[34ml�[39m�[35my�[39m�[31m:�[39m Binding route :: get /csrfToken (FUNCTION: csrfToken)
�[36mverbose: �[39mAll hooks were loaded successfully.
�[36mverbose: �[39mStarting app at /home/shumailarshad/nodeProjects/sailsApp...
�[36mverbose: �[39mRunning the setup logic in sails.config.bootstrap(cb)...
�[32minfo: �[39m
�[32minfo: �[39m .-..-.
�[32minfo: �[39m
�[32minfo: �[39m Sails <| .-..-.
�[32minfo: �[39m v0.12.0-rc3 |
�[32minfo: �[39m /|.
�[32minfo: �[39m / ||
�[32minfo: �[39m ,' |'
�[32minfo: �[39m .-'.-==|/_--'
�[32minfo: �[39m --'-------' �[32minfo: �[39m __---_**--**_---**_--**_---**_--___ �[32minfo: �[39m ____---**_--**_---**_--**_---**_--**_-__ �[32minfo: �[39m �[32minfo: �[39mServer lifted in /home/shumailarshad/nodeProjects/sailsApp�[32minfo: �[39mTo see your app, visit �[4mhttp://localhost:1337�[24m �[32minfo: �[39mTo shut down Sails, press <CTRL> + C at any time. �[37m�[39m �[37m�[39m �[36mverbose: �[39mCould not fetch session, since connecting socket has no cookie (is this a cross-origin socket?) Generated a one-time-use cookie:sails.sid=s%3AhZ37GCPEKTcQX_yWauJWIZdT-6ifP4-K.BV5Ae2aYePNF3xYWFyETAGYaQQDlOhG8%2BYLW0y7tfwQand saved it on the socket handshake. This will start this socket off with an empty session, i.e. (req.session === {}) That "anonymous" section will only last until the socket is disconnected unless you persist the session id in your database, or by setting the set-cookie response header for an HTTP request that you _know_ came from the same user (etc) Alternatively, just make sure the socket sends acookieheader or query param when it initially connects. �[36mverbose: �[39mCould not fetch session, since connecting socket has no cookie (is this a cross-origin socket?) Generated a one-time-use cookie:sails.sid=s%3AfUrwmeyu-0OQwxytJfZFDhXLOZ4dJOzE.krmwG1mMKkj9Bwb90QyQJc%2FkNqhuKMJI3UHZaEuwdh8and saved it on the socket handshake. This will start this socket off with an empty session, i.e. (req.session === {}) That "anonymous" section will only last until the socket is disconnected unless you persist the session id in your database, or by setting the set-cookie response header for an HTTP request that you _know_ came from the same user (etc) Alternatively, just make sure the socket sends acookieheader or query param when it initially connects. �[36mverbose: �[39mCould not fetch session, since connecting socket has no cookie (is this a cross-origin socket?) Generated a one-time-use cookie:sails.sid=s%3AzYFy363qGzLWc2VQvySDuRLCD__V0zpn.fkaSgJYvhBEIQuoZy%2F4ToP6bKK19qu%2BWA8Xnvzm8lN4and saved it on the socket handshake. This will start this socket off with an empty session, i.e. (req.session === {}) That "anonymous" section will only last until the socket is disconnected unless you persist the session id in your database, or by setting the set-cookie response header for an HTTP request that you _know_ came from the same user (etc) Alternatively, just make sure the socket sends acookie` header or query param when it initially connects.
�[36mverbose: �[39mCould not fetch session, since connecting socket has no cookie (is this a cross-origin socket?)
Generated a one-time-use cookie:sails.sid=s%3AjF2Ze-C0DmsfyO2hhtEdMcxbkXhsFyIS.yJInQlHK7%2BF41uITREYvit1hPzr06ec3F%2B5SbrgCb9Aand saved it on the socket handshake.

"""""""""""""

@richdunajewski
Copy link

Looks like something is opening a websocket connection over and over. Wondering if:

a) a websocket client is attempting to connect; or
b) PM2 is trying to connect for some reason (less likely); or
c) Sails/Socket.io is interpreting the cluster connections as websocket connections (is this even possible?)

You said you're not even hitting the app, so that should rule out a) above.

Given the high amount of socket connections, the memory usage is probably coming from using sails-memory as the default socket/session adapter, so all this data is being stuffed in RAM rather than a data store of some kind.

Anyone else have a hunch on what could be going on?

@Josebaseba
Copy link
Contributor

It seems like the sockets sessions are saving and saving all the time in a loop, don't know why. Try disabling the sockets this time and check the memory (.sailsrc file again):

{
  "hooks": {
    "sockets": false,
    "pubsub": false
  }
}

@shumailarshad
Copy link
Author

Right, after applying above change, it is stable.

screenshot from 2015-07-23 17 04 26

Now, we need to know, how to fix this issue. Whats happening?

@sgress454
Copy link
Member

@shumailarshad do you have a browser window open, pointed at the http://localhost:1337? The default sails.io.js library attempts to reconnect sockets after Sails is lowered and relifted, which would account for your logs.

@Josebaseba
Copy link
Contributor

@sgress454 but 4GB of data on empty sessions is too much for just a browser connecting and disconnecting for few hours... And that just happens in cluster mode, I can't figure what's going there.

@richdunajewski
Copy link

Not sure if this is the solution, but I found this thread over at PM2: Unitech/pm2#81

Using the memory adapter for socket sessions when clustered could cause issues, since your session would exist in memory of one process but not the others. Obviously you'd want to use a data store like Redis to solve this, but in @shumailarshad's case, he hasn't gotten far enough to play around with sockets and may not even want them yet.

He did say that he wasn't even hitting the URL, so if that's true then sails.io.js file should not even be running and trying to connect. 4GB is still insane, though, but I wanted to mention the above issue in case that has something to do with it.

@sgress454
Copy link
Member

Actually, Sails apps using the latest version of sails-hook-sockets do make their own socket connection on the backend, so that in a clustered situation all of the Sails apps in the cluster can communicate over a message bus (see #3008 (comment)). So if the log only has one of those "Could not fetch session" messages per app in the cluster, that's expected. Of course it still doesn't explain the memory leak (or its growth over time).

@soyuka
Copy link

soyuka commented Jul 29, 2015

I've done a few tests with express, sails and a basic http server : https://github.com/soyuka/nodejs-http-memtest. Sails seems to be leaking :

@Josebaseba
Copy link
Contributor

@soyuka take a look here: #2779 probably you have that memory increase because of the session storage, sails save it in the RAM. To fix it disable the sessions or just use an adaptor as redis-session.

That's not the problem, the problem is that the memory increases in the cluster mode + sockets/pub-sub hooks, that's the weird stuff.

@soyuka
Copy link

soyuka commented Jul 29, 2015

@Josebaseba What are you meaning by session storage? Can you quote docs or some code please?
I'm not familiar with sailsjs at all.
Anyway, I don't see why Sailsjs would require almost 1.6gb of ram only by spamming a single http route.

@Josebaseba
Copy link
Contributor

@soyuka take a look at this specific comment: #2779 (comment)

@soyuka
Copy link

soyuka commented Jul 29, 2015

@Josebaseba I have read this comment but can't find docs on how I could disable sessions. I noticed the config/session but I don't want to use any adapter.

@Josebaseba
Copy link
Contributor

http://stackoverflow.com/questions/28015873/disable-some-built-in-functionality-in-sails-js/28017720#28017720 try this, but just disabling session hook, and then tell us your results. Thanks!

@soyuka
Copy link

soyuka commented Jul 29, 2015

ok that's fine now:

Never mind, not the issue here, and I was just searching if it was a pm2 leak or not :).

Gl with this one!

@sgress454
Copy link
Member

@Josebaseba thanks for your help on this, definitely an important thing to keep in mind when doing stress tests!

@sgress454
Copy link
Member

@jacqueslareau @AlejandroJL I know this is a stupid question, but when you say that upgrading Node fixed the problem, you are taking into account the fact that restarting your Sails app will drop the memory usage to zero (or more accurately, the baseline amount of memory usage), right? In both of your graphs, the memory starts going up again.

@AlejandroJL
Copy link

Hi @sgress454 . The difference in my case is that now the memory goes freeing is little bit. Before it was not up to quite large quantities with a super traffic reduced (in testing phase). It is clear that it is not the solution but at least an improvement is seen. Now as we need to see the behavior of NodeJS 4.0.0. In the case of my chart if that took into account the reboot. And soon see ram is freed of little.

@AlejandroJL
Copy link

New graphics

captura de pantalla 2015-09-11 a las 18 33 27

@jacqueslareau
Copy link

@sgress454 I took that into account yes. Before 4.0.0, it didn't took long before the memory gets consumed. See this graph:

omega sails memory-more

While it's true that I may have been over excited, it still is a major improvement. Well keep posted.

@particlebanana
Copy link
Contributor

@AlejandroJL @jacqueslareau I ran the same app on node 0.10.x with no memory leaks then ran it on 0.12.x and saw the leak. Haven't tried it on iojs or node 4.0 yet.

@Ignigena
Copy link
Contributor

@particlebanana fwiw my experience is identical. Previously my app was running on 0.10 and never exceeded about 200MB or so of memory. Once upgrading my dyno to 0.12 the leak started. I've been able to mitigate this somewhat on Heroku by using the --max_old_space_size flag since I noticed all my heap dumps were similarly sized at only 40-50MB in size.

Going to attempt a jump to 4.0 and see if this changes things...

@AlejandroJL
Copy link

Hey @particlebanana we are currently experimenting with 4.0. And we see improvements. in the previous comments you have graphs with NodeJS 4.0

@martingg88
Copy link

yes.. i have experienced memory leak for sails using with node 0.12.7 version even before and after turn off hooks. maybe will try nodejs 4.0. hope someone else can solve this issue. thanks.

@tjwebb
Copy link
Contributor

tjwebb commented Sep 14, 2015

Once upgrading my dyno to 0.12 the leak started

The explanation is as simple as you'd think it is: node 0.12 simply uses more RAM and doesn't garbage collect as aggressively.

@codebykenny
Copy link

Out of curiousity how are you folks getting sails to run with v4.0? Is there a workaround to the seg faults happening with socket.io?

@tjwebb
Copy link
Contributor

tjwebb commented Sep 14, 2015

@kennysmoothx see #3211

@martingg88
Copy link

don't think nodejs 4.0 will solve the memory after tried.

@Ignigena
Copy link
Contributor

@kennysmoothx I'm not getting the same seg-faults on v4 both locally and deployed on Heroku. I did have to make some updates to the .travis.yml to make the build run smoothly there, but otherwise I've had no issues.

@tjwebb I do think my particular issue (and potentially others too) may be related to the garbage collection in Node. I was tipped off to this because my heap dumps were nearly identical in size both at deployment and once memory was pegged out several hours later. I had also already done the suggested steps of moving sessions and sockets off of disk storage.

Node v4 wasn't a magic bullet fix for me. My solution has been to set the --max_old_space_size flag at around 50-60% of available memory (in MB) on the deployed instance. I'm still seeing shark teeth in the memory graphs but I've at least stopped exceeding memory and experiencing the resulting performance degradation in production.

@jacqueslareau
Copy link

Here is a followup after 5 days. I observe the same thing on my other sails apps.

omega sails memory-suite

@mikermcneil
Copy link
Member

@jacqueslareau @Ignigena thanks for the follow up- and please keep us posted. Keeping a close eye on this.

@sgress454
Copy link
Member

Following up on this--are we prepared to chalk this up to a Node issue and close, or should we still be looking at a possible issue in Sails? @jacqueslareau @Ignigena have things continued to be stable?

@jacqueslareau
Copy link

Still no more memory leaks for me. But my observations are anecdotal at best. Maybe something else I didn't see played a role in my leaks, but I highly doubt it. It would require more debugging and tests.

@sgress454
Copy link
Member

Ok--closing for now. Thanks again for everyone's hard work on this.

@mikermcneil
Copy link
Member

@sgress454 👍

@kailashyogeshwar85
Copy link

Hi all ,

I found this issue which i was facing on my staging and production server . Previously i was using node v 0.12.4 with passenger used for deployment and on fresh restart the memory consumption went from 13 to 14 % to 43% without any request and using loadtest to just hit the server url consumed more memory which i am yet to resolve ( may be its the socket and session that uses ram for storage ) . We then migrated to node v 4.0.24 which had better gc policy and cleared off the unused memory better than v 0.12.4 and i switched from passenger to PM2 which reduced another consumption in memory and now on fresh start up the consumption is just about 9 to 10 % and on full load it may increase to 14 to 18 % but not more than that.

If there is an issue with socket or session using RAM we would like to know another alternate solution so that we can optimize our server more.

@irlnathan
Copy link
Contributor

@kailashyogeshwar85 Howdy. Please open a new issue. Thanks!

Best, Irl

Kaweechelchen pushed a commit to TfLlu/TfL-Dashboard-generator that referenced this issue Apr 17, 2016
Kaweechelchen pushed a commit to TfLlu/TfL-API that referenced this issue Apr 17, 2016
@mikermcneil
Copy link
Member

@kailashyogeshwar85 check out #3638 (comment) for more exploration of your question about sessions.

More generally, I wrote up some more info/tips/best practices for diagnosing suspected memory leaks in a Node/Sails application here. If you notice issues after running through those troubleshooting steps, please open a new issue to make sure we see it, and we'll look into it ASAP.

Thanks again!

@mikermcneil
Copy link
Member

An update with more info and tips:
#3782 (comment)

@balderdashy balderdashy locked and limited conversation to collaborators Aug 9, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests