Skip to content

fix: retry transient 5xx errors during token refresh - #27

Merged
marcusolsson merged 1 commit into
mainfrom
fix/issue-7-retry-transient-5xx
May 21, 2026
Merged

fix: retry transient 5xx errors during token refresh#27
marcusolsson merged 1 commit into
mainfrom
fix/issue-7-retry-transient-5xx

Conversation

@marcusolsson

Copy link
Copy Markdown
Contributor

Issue 7 from TODO.md

A single 503 Service Unavailable from the refresh endpoint immediately bubbled up as a fatal error. In distributed systems, transient 5xx errors are common during deployments or brief overloads.

Changes

  • Adds attempt parameter (default 1) to refreshAccessTokenInternal.
  • On 5xx-class responses with attempt <= 2:
    • Delay: 500ms on first retry, 1500ms on second.
    • Log the retry attempt.
    • Recurse with attempt + 1.
  • 4xx client errors are NOT retried (they're deterministic failures).
  • refreshInFlight deduplication prevents the thundering-herd problem.

Tests

  • Single 503 -> retry once -> success on second call.
  • Two consecutive 503s -> fail after exhausting retries.
  • 401 -> no retry, immediate failure.

Refs: TODO.md Issue 7

@marcusolsson
marcusolsson merged commit 78f7ebd into main May 21, 2026
@marcusolsson
marcusolsson deleted the fix/issue-7-retry-transient-5xx branch May 21, 2026 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant