Skip to content

Race condition: store.get() called before session.save() is complete #309

@jamesplease

Description

@jamesplease

Sometimes, when a user signs into my app, they are registered as not being logged in. I've narrowed it down to what seems to be a race condition in this library.

The tl;dr is that the .save() function is called from the index.js file of this library, initiating the process of saving the session to the DB. However, the middleware continues on its way, calling .get() before the session has saved. Therefore, it doesn't find the session, and doesn't set it to req.session.

This leads Passport downstream to think that the user isn't authenticated. When the user refreshes, typically the save has finished at that time, and they are now logged in.

Has anyone encountered this before?

I'm using this with Passport and simple-pg-connect for persisting the session to the DB, but every other piece to the puzzle seems to be working correctly except for this one (at least, from what I can gather).

The project that this is going in is open source. The middleware is being configured here:

https://github.com/jmeas/finance-app/blob/google-sign-in/server/app.js

and the Passport configuration can be seen here:

https://github.com/jmeas/finance-app/blob/google-sign-in/server/utils/configure-passport.js

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions