Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MemoryStore leaking memory in SailsJs App

Tags:

sails.js

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?

like image 984
windchime Avatar asked Sep 13 '15 02:09

windchime


1 Answers

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:'
};
like image 65
Eugene Obrezkov Avatar answered Nov 12 '22 10:11

Eugene Obrezkov