7

A few days ago, I run SailsJs app for the first time in production. This warning showed up.

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

I understand that a similar question has been asked and the answer seems to be periodically cleaning up sessionStore with code like.

function sessionCleanup() {
   sessionStore.all(function(err, sessions) {
      for (var i = 0; i < sessions.length; i++) {
         sessionStore.get(sessions[i], function() {} );
      }
   });
}

How can I get reference to sessionStore in sails.js?

Community
  • 1
  • 1
windchime
  • 1,253
  • 16
  • 37
  • You better don't use MemoryStore at all. If you will store data in memory in production mode then you'll face many problems with scaling. – Eugene Obrezkov Sep 13 '15 at 07:06
  • how can I disable it? – windchime Sep 13 '15 at 17:26
  • Just update your Sails config where you are set up session configuration. – Eugene Obrezkov Sep 13 '15 at 17:28
  • My session configuration(config/session.js) only has a secret property. Nothing else. After reading Sails documentation and comments inside, I still could not find a way to disable sessionStore. – windchime Sep 13 '15 at 17:33
  • You must provide another adapter for your session storage also. Take a look at full example - http://sailsjs.org/documentation/anatomy/my-app/config/session-js – Eugene Obrezkov Sep 13 '15 at 17:42
  • Is the only thing I need to do is to provide another adapter for my session storage? Do I need to change something else to disable the default session storage? I could not find anything in that example which turned off sessionStore. – windchime Sep 13 '15 at 17:52
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/89518/discussion-between-eugene-obrezkov-and-windchime). – Eugene Obrezkov Sep 13 '15 at 17:53
  • The change makes the warning disappear. Thank you – windchime Sep 16 '15 at 02:33

1 Answers1

5

All what you need to do is just replace memory adapter in config/session.js with another adapter, Redis, for instance.

module.exports.session = {
  secret: '<YOUR_SECRET>',
  adapter: 'redis',
  host: 'localhost',
  port: 6379,
  ttl: <REDIS_TTL_IN_SECONDS>,
  pass: <REDIS_PASSWORD>
  prefix: 'sess:'
};
Eugene Obrezkov
  • 2,910
  • 2
  • 17
  • 34