-
Notifications
You must be signed in to change notification settings - Fork 180
Race condition in RefreshTokenDelegatingHandler #266
Comments
I can acknowledge this is an actual issue, we are having the same issue on our side. We believe the issue lies in the fact that the retrieval of the refresh token is not contained within the critical section of the lock where the actual refresh happens (see code sample from Nickolas) This allows a second call, that was awaiting the lock, to use an old value of the refresh token, even after a first call successfully refreshed the tokens. The result is as @Nickolas- described, that the second call fails to refresh the tokens, because it cannot find the handle anymore in the PersistedGrants (because the first call successfully refreshed both access and refresh tokens). We just discovered this issue in our mobile app, we will try to work around this by implementing the RefreshTokenDelegatingHandler ourselves, and refactor the Something like this:
|
This reverts commit a773a6c. Consistently green on the local machine.
…#303) * initial test * tests which demonstrate the race condition (and the need to run the handler as a singleton) * remove singleton test * fixed race condition on RefreshTokenDelegatingHandler (only happens when using refresh tokens with sliding expirations) * fix overly strict test * Revert "fixed race condition on RefreshTokenDelegatingHandler (only happens when using refresh tokens with sliding expirations)" This reverts commit 21c8f1c. * updated test fails regularly on my local machine * Reintroduced the fix for issue #266 again This reverts commit a773a6c. Consistently green on the local machine. Co-authored-by: Jochen Zeischka <[email protected]>
Hi, im not familiar is it expected behaviour or Im using library not in proper way, but...
If add
RefreshTokenDelegatingHandler
inHttpClient
pipe , you would get Unauthorized http response when you have a valid refresh token. This cause byprivate async Task<bool> RefreshTokensAsync(CancellationToken cancellationToken)
When you run two http requests in parallel with invalid access token it would cause a race condition in logic.
Issue would be if one request finish work earlier than other. For example from the beginning refreshToken is equal to "FIRST". First call of RefreshTokensAsync would return that refreshToken is "TWO" , but previous http request would be still try to refresh token with token "FIRST" and would return response with error because that token is not exist in IS anymore. Can anyone give me some thoughts about it.
The text was updated successfully, but these errors were encountered: