express-admin icon indicating copy to clipboard operation
express-admin copied to clipboard

What about memory leaks?

Open ghost opened this issue 9 years ago • 8 comments

Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.

ghost avatar Jun 13 '15 17:06 ghost

I can't remember seeing that error. Are you sure this isn't something used in your own application?

simov avatar Jun 15 '15 07:06 simov

No, I have separate express admin app and log. This message shows up only when NODE_ENV environment variable is set to "production". 2015-06-15 22-43-27 environment variables 2015-06-15 22-44-11 spbushare - c users r2d2 documents programming spbushare - express-admin-cfg-dev settings json -

ghost avatar Jun 15 '15 19:06 ghost

Here is the one of solutions: http://stackoverflow.com/questions/10760620/using-memorystore-in-production

ghost avatar Jun 15 '15 19:06 ghost

I still don't see what this have to do with express admin. Express Admin uses Express4 which in turn does not use Connect, or am I wrong?

simov avatar Jun 15 '15 20:06 simov

You can reproduce it. Just set NODE_ENV="production" and start Express Admin.

ghost avatar Jun 15 '15 23:06 ghost

Here is the explanation: https://github.com/expressjs/session#api

ghost avatar Jun 15 '15 23:06 ghost

Got it, ideally the session store should be configurable, but currently it's not.

simov avatar Jun 16 '15 03:06 simov

Ok looks like we can use some properties that can control this behavior: interval, maxAge, cookie, saveUninitialized, resave .. etc

More can be found here: MongoDB fix: connection.session() MemoryStore is not designed for a production environment

Also that there are some hacks around this error, for example:

  • Handle the error instead of crashing: https://stackoverflow.com/a/44884800/5890227

  • use cookie-session instead of express-session: https://stackoverflow.com/a/37022764/5890227

  • And/Or to force-clean all sessions in a custom function on our own: https://stackoverflow.com/a/10761522/5890227

I had same issue and did a quick research which is worth sharing. Hope it helps!

KhalilKhalaf avatar Oct 02 '17 15:10 KhalilKhalaf