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

A race condition invalidateToken while authenticating a request #412

Open
ChangXiaoning opened this issue Jan 9, 2019 · 3 comments
Open

Comments

@ChangXiaoning
Copy link

It is a race in services/keystoneAuth.js.

I want to call invalidateToken() function to clear currentToken (i.e., set currentToken to null) and then validate other requests using authenticate() function. Then, authenticate() function checks whether currentToken is null, if it is null, it will authenticate the request asynchronously, using request(options, cb). However, another asynchronous authenticating request can return at this time, which sets the currentToken to req.token and impacts the currentToken to non-null (I have called invalidateToken to null to authenticate following request).

@fgalan
Copy link
Member

fgalan commented Jan 9, 2019

Thank you for the detailed report!

It seems you have looked to the problem very closely. Maybe it would a good idea to do a pull request with a proposed fix so we can evaluate it, please? Thanks again!

@AlvaroVega
Copy link
Member

AlvaroVega commented Jul 28, 2020

But invalidateToken is called by nobody:

function invalidateToken(callback) {

and currentToken is set to null by retrieveRequest functions.

If that currentToken is set to null in the meantime of authenticate and then fail, some retries (3) will be performed and then no race condition effects will matter.

@ChangXiaoning
Copy link
Author

ChangXiaoning commented Apr 12, 2021

@AlvaroVega Hi, I have a question: you explain that "If that currentToken is set to null in the meantime of authenticate and then fail, some retries (3) will be performed and then no race condition effects will matter". I think the effect in this case is that, it wastes some requests (because the useful currentToken is overwritten by null) and following retries(3) will be performed and retrives the same useful currentToken. In other words, "waste" means an effect of performance degradation. Thanks again!

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