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

Race condition issue? #44

Open
jamesplease opened this issue Apr 23, 2017 · 0 comments
Open

Race condition issue? #44

jamesplease opened this issue Apr 23, 2017 · 0 comments

Comments

@jamesplease
Copy link

jamesplease commented Apr 23, 2017

Hi there – awesome project!

I'm wondering if there's a small bug around this code.

When the if statement matches, an attempt is made to update the user before passing it along to done. However, the call to done immediately after the if statement will likely always resolve before the update to the user completes.

This probably wouldn't affect some applications, because the update call is getting instantiated. But the middleware is likely moving onto to the next middleware a little earlier than expected.

Another consequence of this is that done will get called twice, which I'm pretty sure goes against the contract of how done is intended to be used.

I'm thinking it should instead be:

if (!user.facebook.token) {
  user.facebook.token = token;
  user.facebook.name  = profile.name.givenName + ' ' + profile.name.familyName;
  user.facebook.email = profile.emails[0].value;

  user.save(function(err) {
    if (err)
      throw err;
    return done(null, user);
  });
} else {
  return done(null, user); // user found, return that user
}

This issue likely affects the other services' code, too. What do you think?

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

1 participant