Fix stale tokens returned during concurrent refresh-token renewal#2186
Open
ThorstenKunz wants to merge 1 commit intodamienbod:mainfrom
Open
Fix stale tokens returned during concurrent refresh-token renewal#2186ThorstenKunz wants to merge 1 commit intodamienbod:mainfrom
ThorstenKunz wants to merge 1 commit intodamienbod:mainfrom
Conversation
Enhances the session refresh handling process by waiting for an ongoing renew process to complete before attempting a refresh, ensuring token consistency. Introduces new integration tests to verify the behavior and updates the IDP server to support refresh tokens. This change addresses potential race conditions where concurrent session refresh calls may lead to stale or inconsistent tokens.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a race condition in the refresh-token flow where concurrent
forceRefreshSession()calls could return stale tokens or observe inconsistent auth state.Problem
In refresh-token mode,
forceRefreshSession()built itsLoginResponsefrom the current auth-state getters instead of preferring the fresh result from the completed refresh operation.This became problematic when multiple refresh calls happened close together:
Reproduction
The issue can be reproduced with a client configured with
useRefreshToken: trueby triggering multiple manual refresh calls in parallel:Before the fix, returned tokens and immediately readable stored tokens could diverge depending on timing.
Fix
The refresh flow was changed in three key places:
authResultof the completed refresh operation when creating theLoginResponse.NewAuthenticationResultevent before completing.Test Coverage
This PR adds regression coverage for both unit and integration scenarios:
forceRefreshSession()calls withuseRefreshToken: true,Result
After this change, concurrent manual refresh calls resolve consistently and return the freshly renewed token set instead of stale auth-state values.