Q43: How do you handle race conditions during concurrent API requests using Refresh Token Rotation?

Difficulty:AdvancedTopic:Concurrency & Security

In browser applications executing concurrent API calls (e.g., rendering dashboard widgets simultaneously), an expired access token can cause multiple HTTP requests to trigger simultaneous refresh calls.

If strict Refresh Token Rotation is enforced, the first request succeeds, but concurrent secondary refresh calls present the old invalidated token, causing false-positive reuse detection triggering forced user logouts.

Solution Patterns:

  1. Client Request Queueing: Intercept 401s; queue parallel failed calls behind a single active token refresh Promise.
  2. Server Grace Period: Auth Server permits a brief grace window (e.g., 10-30 seconds) where the old refresh token remains valid for identical concurrent refresh requests.
Key Takeaways
  • Parallel API refresh requests trigger false-positive token reuse detections without handling.

  • Mitigate using client-side promise queuing or server-side refresh token grace periods.