Bug report: Race condition in Flutter SDK `createOAuth2Session` / `client_io.dart
- 0
- Flutter
- Auth
Hi team,
I've found an intermittent bug in the Flutter SDK (v20.3.0) when using createOAuth2Session on Android.
Symptoms
After createOAuth2Session resolves, an immediate call to _account.get() intermittently throws:
AppwriteException: general_unauthorized_scope,
User (role: guests) missing scopes (["account"]) (401)
Root cause
In client_io.dart, the webAuth method resolves the Future immediately after:
_cookieJar.saveFromResponse(Uri.parse(_endPoint), cookies);
saveFromResponse is an async write operation that may not have fully persisted the session cookies by the time the caller makes the next API call. This creates a race condition between cookie persistence and subsequent authenticated requests.
Reproduction
- Android device
- OAuth2 provider: Google
- Call
createOAuth2Sessionfollowed immediately by_account.get() - Intermittent in debug mode, less frequent in release mode
Workaround
Retry _account.get() with exponential backoff after a 401 response.
Suggested fix
Ensure saveFromResponse is fully awaited and the cookie jar is flushed before resolving the Future in webAuth.
Recommended threads
- Error With iOS Apps
I keep getting the below errors for my flutter app. The clients are registered and have been. This wasn't an issue a few hours ago. AppwriteException: AppwriteE...
- TEAM INVITE
There is a problem with the team invitation. When a user invites other users, that time, the newly created email address they don't get the invite link and old ...
- 500 simultaneous OAuth logins from the s...
Hi, I'd like to ask about rate limiting around Google OAuth login on Appwrite Cloud. **OVERVIEW** Service type: A PWA (web app) for members of a university clu...