Describe the bug
I'm testing the token expiration behaviour on iOS, so I've set the refresh token expiration to 60 mins.
If the token is expired, on the next app launch, the app will crash with EXC_BREAKPOINT
* thread aws-amplify/amplify-flutter#5, queue = 'com.apple.NSURLSession-delegate', stop reason = EXC_BREAKPOINT (code=1, subcode=0x1888757d8)
frame #0: 0x00000001888757d8 libdispatch.dylib`dispatch_group_leave.cold.1 + 36
libdispatch.dylib`dispatch_group_leave.cold.1:
-> 0x1888757d8 <+36>: brk #0x1
libdispatch.dylib`dispatch_group_enter.cold.1:
0x1888757dc <+0>: mov x0, x30
0x1888757e0 <+4>: bl 0x18884347c ; OUTLINED_FUNCTION_0
0x1888757e4 <+8>: mov x30, x0
Target 0: (Runner) stopped.
Lost connection to device.
To Reproduce
Steps to reproduce the behavior:
signOut, the IOS browser redirect dialog will be shown saying "Do you want to open awscognito.com blabla". If user clicked agree, then the signOut succeeds and nothing happens. However, the issue occurs when user clicked Cancel on this dialog.Platform
Amplify Flutter current supports iOS and Android. This issue is reproducible in (check all that apply):
[] Android
[X] iOS
flutter doctor -v
```[✓] Flutter (Channel stable, 2.0.1, on macOS 11.2.2 20D80 darwin-x64, locale en-GB)
• Flutter version 2.0.1 at /Users/fanwg/Library/flutter
• Framework revision c5a4b4029c (7 days ago), 2021-03-04 09:47:48 -0800
• Engine revision 40441def69
• Dart version 2.12.0
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /Users/fanwg/Library/Android/sdk
• Platform android-30, build-tools 30.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.4, Build version 12D4e
• CocoaPods version 1.10.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
[✓] VS Code (version 1.54.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.20.0
[✓] Connected device (1 available)
• Chrome (web) • chrome • web-javascript • Google Chrome 89.0.4389.82
• No issues found!
```
Smartphone (please complete the following information):
Additional context
See this for the detailed stacktrace, the crash happens at the line self.tokenFetchLock.leave() in AWSMobileClient#releaseSignInWait()

Thanks! I've been digging this issue for two days and not having any clues yet :(
After experimenting with a few different coding logics, I'm suspecting that the following flow will lead to the crash:
Amplify.Auth.fetchAuthSession() (note that isSignedIn is still true for a user with session expired)Amplify.Auth.getCurrentUser()(note that a valid AuthUser is still returned for a user with session expired)Amplify.Auth.fetchUserAttributes()If the hub event of SESSION_EXPIRED arrives between 2 and 3, then the app will crash at 3. Note that I have a chaining call of 1.then(2).then(3), because I don't know about session expiration until the hub event, so there is no way that prevents me from calling 3.
However, the same flow works fine in Android.
@fanwgwg Thanks for posting this, we're taking a look.
@fanwgwg I am transferring this to the amplify-ios repo so they can take a look.
Any updates on this?
After experimenting with a few different coding logics, I'm suspecting that the following flow will lead to the crash:
- Check isSignedIn via
Amplify.Auth.fetchAuthSession()(note that isSignedIn is still true for a user with session expired)- Get current user via
Amplify.Auth.getCurrentUser()(note that a validAuthUseris still returned for a user with session expired)- Get user email via
Amplify.Auth.fetchUserAttributes()If the hub event of
SESSION_EXPIREDarrives between 2 and 3, then the app will crash at 3. Note that I have a chaining call of1.then(2).then(3), because I don't know about session expiration until the hub event, so there is no way that prevents me from calling 3.However, the same flow works fine in Android.
Sorry for the late reply. I just managed to reproduce the issue.
No need to call getCurrentUser() that I can see the crash.
Every time the App launches, my App will do a fetchAuthSession()
The reproduction step is:
sign in with google..sessionExpired while still in the App. I receive one when I relaunch the App.fetchUserAttributes() which causes the crash.@ruiguoamz Thanks for looking in to it, is there any estimate on when this issue can be fixed?
any updates guys?
This issue is stale because it has been open for 14 days with no activity. Please, provide an update or it will be automatically closed in 7 days.
just to keep the bug alive, still occurring on 2.23.2
I am experiencing the same crash in my app as well with web UI logins (specifically sign in with apple) and the same flow as above. Any updates on this?


This issue should be fixed by this PR - https://github.com/aws-amplify/aws-sdk-ios/pull/3501 , pending release.
@royjit any idea when a release is going to happen? This bug has been crashing my app for some time and I'd like to get this squashed ASAP.
we are aiming to release it this week
We released this on 2.24.1.
Most helpful comment
This issue should be fixed by this PR - https://github.com/aws-amplify/aws-sdk-ios/pull/3501 , pending release.