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

better solution for disconnected store #4

Open
jonathanong opened this Issue Feb 16, 2014 · 5 comments

Comments

Projects
None yet
4 participants
@jonathanong
Member

jonathanong commented Feb 16, 2014

migrated from senchalabs/connect#973

@Fishrock123

This comment has been minimized.

Show comment
Hide comment
@Fishrock123

Fishrock123 May 29, 2014

Member

Is it reasonable to just default to a cookie store for this when another store is unavailable?

(or you could just have it cache it in a temporary memory store, but that seems like a bad idea..)

Member

Fishrock123 commented May 29, 2014

Is it reasonable to just default to a cookie store for this when another store is unavailable?

(or you could just have it cache it in a temporary memory store, but that seems like a bad idea..)

@jonathanong

This comment has been minimized.

Show comment
Hide comment
@jonathanong

jonathanong May 29, 2014

Member

naw. these sessions could be humongous

Member

jonathanong commented May 29, 2014

naw. these sessions could be humongous

@dougwilson

This comment has been minimized.

Show comment
Hide comment
@dougwilson

dougwilson May 29, 2014

Member

Is it reasonable to just default to a cookie store for this when another store is unavailable?

plus if it is unavailable, how would you get the data out of the store to put into the cookie? :)

Member

dougwilson commented May 29, 2014

Is it reasonable to just default to a cookie store for this when another store is unavailable?

plus if it is unavailable, how would you get the data out of the store to put into the cookie? :)

@paton

This comment has been minimized.

Show comment
Hide comment
@paton

paton Jul 23, 2014

I experienced undefined req.session every so often caused by a disconnected redis store (using ElastiCache).

Here's a workaround that recreates the session middleware with a new Redis connection when the old connection disconnects.

Not sure if it would make sense to attempt a reconnect in the module itself.

app.use((function(){
  var sessionMiddleware;

  var createMiddlware = _.throttle(function() {
    var store = new RedisStore({ ... });
    store.on('disconnect', createMiddlware);

    sessionMiddleware = session({
      store: store,
      cookie: { maxAge: 60000 },
    });
  }, 2000);

  createMiddlware();

  return function(req, res, next) {
    sessionMiddleware.apply(this, arguments);
  };
})());

app.use(function(req, res, next) {
  if (req.session) return next();
  res.send(500, 'Servers are updating. Please check back soon.');
});

paton commented Jul 23, 2014

I experienced undefined req.session every so often caused by a disconnected redis store (using ElastiCache).

Here's a workaround that recreates the session middleware with a new Redis connection when the old connection disconnects.

Not sure if it would make sense to attempt a reconnect in the module itself.

app.use((function(){
  var sessionMiddleware;

  var createMiddlware = _.throttle(function() {
    var store = new RedisStore({ ... });
    store.on('disconnect', createMiddlware);

    sessionMiddleware = session({
      store: store,
      cookie: { maxAge: 60000 },
    });
  }, 2000);

  createMiddlware();

  return function(req, res, next) {
    sessionMiddleware.apply(this, arguments);
  };
})());

app.use(function(req, res, next) {
  if (req.session) return next();
  res.send(500, 'Servers are updating. Please check back soon.');
});
@dougwilson

This comment has been minimized.

Show comment
Hide comment
@dougwilson

dougwilson Jul 23, 2014

Member

Not sure if it would make sense to attempt a reconnect in the module itself.

It's up to the core to reconnect; the reason this module gives undefined is because you store explicitly told us to do so--a store does not have to do that and just auto-reconnect and you won't experience that, but it's up to the store to do so.

You'll need to report the issue here: https://github.com/visionmedia/connect-redis/issues

Member

dougwilson commented Jul 23, 2014

Not sure if it would make sense to attempt a reconnect in the module itself.

It's up to the core to reconnect; the reason this module gives undefined is because you store explicitly told us to do so--a store does not have to do that and just auto-reconnect and you won't experience that, but it's up to the store to do so.

You'll need to report the issue here: https://github.com/visionmedia/connect-redis/issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment