Skip to content

[codex] Serialize token refresh across Dio instances#578

Merged
jjoonleo merged 1 commit into
mainfrom
feature/fix-token-refresh-race
Jun 28, 2026
Merged

[codex] Serialize token refresh across Dio instances#578
jjoonleo merged 1 commit into
mainfrom
feature/fix-token-refresh-race

Conversation

@jjoonleo

Copy link
Copy Markdown
Contributor

What changed

  • Registers AppDio as a lazy singleton so app API callers share one configured Dio client.
  • Moves TokenInterceptor refresh coordination to process-wide state so concurrent 401s across multiple interceptor instances queue behind one refresh request.
  • Adds a regression test for two Dio instances receiving 401s at the same time.
  • Stabilizes a month calendar widget test that could tap a duplicate day from an adjacent month.

Why

Production logs showed default preparation updates returning 200, followed immediately by access/refresh credential failures. The backend rotates refresh tokens, so concurrent refresh attempts with the same old token can make all but the first request fail as stale. Serializing refresh coordination on the client prevents those spurious logout/error paths.

Validation

  • dart run build_runner build --delete-conflicting-outputs
  • flutter test test/core/dio/interceptors/token_interceptor_test.dart
  • flutter analyze
  • flutter test

@jjoonleo jjoonleo force-pushed the feature/fix-token-refresh-race branch from a9c25ef to 6f4497e Compare June 28, 2026 16:57
@jjoonleo jjoonleo marked this pull request as ready for review June 28, 2026 17:12
@jjoonleo jjoonleo merged commit 21db275 into main Jun 28, 2026
3 of 5 checks passed
@jjoonleo jjoonleo deleted the feature/fix-token-refresh-race branch June 28, 2026 17:12
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