Skip to content
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

Session Flash race condition #378

Closed
nemild opened this issue Feb 12, 2016 · 3 comments
Closed

Session Flash race condition #378

nemild opened this issue Feb 12, 2016 · 3 comments

Comments

@nemild
Copy link

nemild commented Feb 12, 2016

Thanks for all the hard work on this!

I noticed a race condition related to the flash. Basically the redirect can complete before the flash is saved to the database - meaning that the flash doesn't show till the next page load (an unfortunate bug for a flash).

I'm unsure if I'm the only one to experience this from hackathon-starter, as I'm using another db rather than the default mongo/mongoose. In theory, it can happen anytime you call (and execute) the redirect, before the session is done saving - and all the redirects in this repo currently don't wait for the session to be saved.

I can send a PR to save the session before redirecting, like this:

req.session.save(function () {
  res.redirect('/login');
}
// Some more code needs to be rewritten in the controllers/user.js so the various functions don't fall through

Before I do, I thought I'd check to see if this has been an issue for others. If not, feel free to close this issue.

@nemild nemild changed the title Session Session Flash race condition Feb 12, 2016
@niallobrien
Copy link
Collaborator

@nemild Curious, what DB are you using?

@nemild
Copy link
Author

nemild commented Feb 12, 2016

@niallobrien Postgres by way of connect-session-sequelize
You can see the relevant issue here, though the issue I noted in the OP was for Mongo.

@sahat
Copy link
Owner

sahat commented Mar 4, 2016

@nemild I am going to close this issue for now since this has never been a problem for me with flash messages. There haven't been any reports of this issue either; until now. In my latest project I am not even using flash messages anymore, but instead render the same page with additional data:

if (errors) {
    return res.render('account/login', {
      title: 'Log in',
      errors: errors
    });
  }

@sahat sahat closed this as completed Mar 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants