express-admin
express-admin copied to clipboard
What about memory leaks?
Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
I can't remember seeing that error. Are you sure this isn't something used in your own application?
No, I have separate express admin app and log. This message shows up only when NODE_ENV environment variable is set to "production".
Here is the one of solutions: http://stackoverflow.com/questions/10760620/using-memorystore-in-production
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?
You can reproduce it. Just set NODE_ENV="production" and start Express Admin.
Here is the explanation: https://github.com/expressjs/session#api
Got it, ideally the session store should be configurable, but currently it's not.
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!