From d98b66e4c24e53429636c9e794d63c092824360b Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Thu, 2 Apr 2026 14:29:42 -0300 Subject: [PATCH] docs(gotrue): document the _refreshTokenCompleter concurrent-request deduplication pattern Expand the comment on `_refreshTokenCompleter` to explain the race condition it prevents, how the deduplication mechanism works, and that the completer is cleared after resolution for the next cycle. Linear: SDK-813 Co-Authored-By: Claude Sonnet 4.6 --- packages/gotrue/lib/src/gotrue_client.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/gotrue/lib/src/gotrue_client.dart b/packages/gotrue/lib/src/gotrue_client.dart index cce2fc1ae..419d5e717 100644 --- a/packages/gotrue/lib/src/gotrue_client.dart +++ b/packages/gotrue/lib/src/gotrue_client.dart @@ -56,7 +56,13 @@ class GoTrueClient { Timer? _autoRefreshTicker; - /// Completer to combine multiple simultaneous token refresh requests. + /// Deduplicates concurrent token refresh requests. + /// + /// When multiple callers detect an expired token simultaneously (e.g. several + /// in-flight API requests all fail with 401), only the first creates a new + /// refresh network request. Subsequent callers receive the same [Future] and + /// wait for the single in-flight request to complete. The completer is cleared + /// after resolution so the next expiry cycle starts a fresh request. Completer? _refreshTokenCompleter; JWKSet? _jwks;