Your application has a valid user session, and everything appears to be working. Then several API requests run at the same time. Their access tokens have expired, so each request tries to refresh its credentials.
The first request succeeds and receives a new access token and refresh token. The remaining requests still hold the old refresh token. Depending on the authorization server's behavior, those requests may fail, trigger refresh-token reuse detection, or force the user to sign in again.
This is a refresh token rotation race condition. It can cause unexpected logouts, failed API calls, and confusing authentication errors even when the user has done nothing wrong.
The core problem is that multiple requests are trying to rotate the same refresh token independently. The solution is to coordinate token refreshes so that one operation updates the credentials and the other requests reuse the result.
What Is Refresh Token Rotation?
OAuth 2.0 uses refresh tokens to obtain new access tokens without requiring the user to authenticate again whenever an access token expires.
With refresh token rotation enabled, the authorization server issues a new refresh token when the client successfully refreshes its access token. The previous refresh token is invalidated, and the server retains enough information to detect attempts to reuse old tokens.
This improves security because a stolen refresh token cannot be used indefinitely without detection.
The OAuth 2.0 Security Best Current Practice, RFC 9700, requires public clients receiving refresh tokens to use sender-constrained refresh tokens or refresh token rotation to detect replay.
However, rotation introduces an important requirement: the client must manage refresh-token state carefully and avoid competing refresh operations using the same credentials.
How Concurrent Requests Cause the Problem
Consider an application whose current refresh token is RT-1. The access token has expired, and three API requests need a fresh one.
| Step | Request A | Request B |
|---|---|---|
| 1 | Reads RT-1 | Reads RT-1 |
| 2 | Sends refresh request | Sends refresh request |
| 3 | Receives AT-2 and RT-2 | Still using RT-1 |
| 4 | Stores new credentials | Attempts to use the old token |
Request A may complete successfully, but Request B can fail because RT-1 has already been consumed.
The situation becomes more serious if the authorization server detects reuse of a rotated refresh token. Some providers revoke the active token family because they cannot reliably distinguish a legitimate client retry from an attacker replaying a stolen token.
The result may be an invalid_grant error, failed API calls, or a session that requires reauthentication. Exact behavior depends on the authorization server and its rotation policy.
Remark: The second request is not necessarily malicious. It may simply be using a token snapshot that became outdated while another request was refreshing the session.
1. Use Single-Flight Refreshing
The most important fix is to allow only one refresh operation at a time for a given session or credential set.
This pattern is often called single-flight or request coalescing. When the first request starts refreshing, subsequent requests wait for that same operation instead of submitting additional refresh requests.
Once the refresh finishes, waiting requests use the result.
The flow becomes:
- A request detects that its access token has expired.
- The authentication client checks whether a refresh operation is already running.
- If no refresh is running, it starts one.
- Other requests await the same operation.
- The new token set is saved, and waiting requests continue with the updated access token.
This is better than letting every failed API request trigger its own refresh attempt.
Remark: The coordination must be scoped to the correct session. A server must never use one global refresh promise or lock for unrelated users.
2. Handle Multiple Browser Tabs and Server Instances
A single-flight promise inside one application instance solves only part of the problem.
Multiple browser tabs can independently attempt to refresh the same session. Similarly, several backend workers or application instances can receive requests for the same user at almost exactly the same time.
Each environment needs coordination appropriate to its architecture.
For browser applications: Prefer your identity provider's supported SDK and session-management mechanisms. If you implement cross-tab coordination, use a shared locking or signaling mechanism so that only one tab refreshes the credentials. Avoid broadcasting raw refresh tokens unnecessarily.
For backend applications: A server-side session store can centralize token management. If multiple application instances share that store, use a per-session distributed lock, conditional update, or another mechanism that coordinates refresh operations across instances.
For browser applications with a backend-for-frontend (BFF), the server can own the refresh tokens and expose the application's authenticated session through a secure session cookie. This can simplify token coordination because browser requests no longer independently rotate the underlying refresh token.
Remark: An in-memory lock works only within the process that owns it. It does not coordinate separate application instances, serverless invocations, or independent browser tabs.
3. Store New Credentials Atomically
Preventing concurrent refreshes is not enough if token storage can still be updated incorrectly.
Suppose one operation receives a new token set, while another operation later writes stale credentials from an earlier read. The application may accidentally overwrite the current refresh token with an older one.
Treat the access token, refresh token, and related metadata as one credential state. Save the new state atomically wherever possible, and prevent an outdated operation from overwriting a newer result.
In a distributed backend, conditional database updates or version checks can help ensure that a worker updates a session only when it still owns the relevant credential state.
This matters because a successful refresh changes the credentials that future requests must use.
Remark: Do not assume that receiving an HTTP response means the new tokens have already been safely persisted. The storage update is part of the refresh workflow, not an optional follow-up.
4. Handle invalid_grant Without Infinite Retries
An invalid_grant response can indicate that a refresh token is invalid, expired, revoked, or no longer accepted. In a concurrent application, it may also occur because another request has already rotated the token.
Do not blindly retry the same refresh request in a loop. If the token has been revoked or reuse detection has invalidated the token family, repeated attempts will not repair the session.
Instead, handle the failure deliberately:
- Check the shared credential state to determine whether another operation successfully refreshed the session.
- If a newer valid token set is available, use it instead of retrying the stale refresh token.
- If the stored credentials are still invalid and no recovery path exists, clear the invalid session and require the user to authenticate again.
This approach avoids unnecessary logouts when another request has already completed the refresh, without assuming that every refresh failure is harmless.
5. Be Careful With Lost Refresh Responses
There is another failure mode that coordination alone cannot completely solve.
Imagine the authorization server successfully rotates RT-1 to RT-2, but the response is lost because of a network failure. The client still has RT-1, even though the server may already have invalidated it.
Retrying with the old token can trigger the same reuse-detection behavior.
Some providers offer a short overlap or grace period during which the immediately previous refresh token can be reused. For example, Auth0 documents refresh token reuse intervals, while Okta documents a configurable rotation grace period.
These settings can help with concurrent or interrupted requests, but they are provider-specific. They are not a replacement for client-side coordination, and their security trade-offs should be understood before changing them.
When a refresh response is lost, use the provider's documented recovery behavior. If no safe recovery mechanism is available and the current credentials cannot be recovered, reauthentication may be necessary.
Remark: A timeout does not prove that the authorization server failed to process the refresh request. Treat the outcome as uncertain until the application can establish which credentials remain valid.
Common Mistakes to Avoid
Refreshing independently from every failed API request. This creates a burst of simultaneous refresh attempts. Centralize or coalesce refresh operations instead.
Using only an in-memory lock for a distributed application. A lock in one process cannot coordinate separate workers or instances.
Overwriting newer tokens with stale credentials. Persist token changes atomically and guard against outdated writes.
Increasing the provider's grace period without fixing concurrency. A grace period can reduce failures, but it is a provider-specific mitigation that may also extend the period during which a previous token is accepted.
Retrying invalid_grant indefinitely. Inspect the latest session state, use any safe recovery mechanism the provider supports, and require reauthentication when the credentials cannot be recovered.
Logging refresh tokens for debugging. These are sensitive credentials. Log useful metadata such as error categories and correlation IDs, but never include raw tokens in application logs.
Conclusion
Refresh token rotation improves OAuth security by limiting the useful lifetime of individual refresh tokens and helping authorization servers detect replay. But applications must account for concurrent requests, especially when several API calls discover an expired access token at the same time.
The most reliable approach is to coordinate refresh operations per session, persist updated credentials safely, handle ambiguous failures deliberately, and use provider-specific grace periods only as an additional safeguard.
If your users experience unexpected logouts or intermittent invalid_grant errors, investigate whether multiple requests are refreshing the same credentials before changing token lifetimes or disabling rotation.
Frequently Asked Questions
Why does refresh token rotation fail with concurrent requests?
Multiple requests may read the same refresh token before any of them finishes refreshing. Once one request rotates the token, the remaining requests may attempt to use an invalidated token and fail.
How do I prevent multiple refresh requests?
Use a single-flight mechanism so concurrent calls share one refresh operation. For multiple tabs or application instances, introduce coordination that works across those contexts rather than relying only on an in-memory promise.
Should I disable refresh token rotation to fix the race condition?
Not as the first solution. Rotation helps detect refresh-token replay, and OAuth security guidance requires public clients to use rotation or sender-constrained refresh tokens when refresh tokens are issued. Fix concurrency handling before considering a change to your security model.
Can a grace period fix refresh token race conditions?
It can reduce failures caused by overlapping requests or lost responses, depending on the provider's implementation. It should be combined with proper refresh coordination rather than treated as a universal solution.
What should I do when a refresh request returns invalid_grant?
Check whether another operation has already saved newer credentials. If not, follow the provider's documented recovery behavior. If the current session cannot be recovered safely, require the user to authenticate again.



