Pick the fix
Five requests fail with 401 at once. Each calls refresh(), the server rotates refresh tokens, and four refreshes fail. Best fix?
Hint 1 of 2
How many refreshes should happen?
Hint 2 of 2
What do the other callers do while one refresh runs?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A An actor stores the in-flight refresh Task; other callers await it; each request retries once
Correct. One refresh, shared by everyone, with a bounded retry.
Why not the others?
- B Put refresh() on a serial DispatchQueue. Refreshes still happen one after another, each with a token that was already rotated.
- C Retry each failed request up to 3 times. That creates even more refreshes and can loop.
- D Refresh on a timer every 5 minutes. Tokens can still expire or be revoked between ticks, and the race remains.