Amplify-ios: EXC_BREAKPOINT crash on iOS when token expired

Created on 11 Mar 2021  Â·  14Comments  Â·  Source: aws-amplify/amplify-ios

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:

  1. Set refresh token to 60 mins, log in the app with social provider (Google in my case)
  2. Keep the app open till session expired (I listen to the hub event for session expiration, upon which I'll show a dialog to the user saying that "you need to log in again" etc). When user clicked on the CTA button on the dialog, I'll sign out the current user and redirect user to the sign in page. However, the current account is from google sign in, so when I called 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.
  3. When user clicked Cancel, and then close the app, on the next app launch, the app will crash.

Platform
Amplify Flutter current supports iOS and Android. This issue is reproducible in (check all that apply):
[] Android
[X] iOS

Output of 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):

  • Device: iPhone 12
  • OS: iOS 14.4 and iOS 14.4.1
  • Browser: Chrome (I set chrome to be the default browser)
  • Version: amplify 0.1.0. I only used amplify auth plugin, no other plugins.

Additional context
See this for the detailed stacktrace, the crash happens at the line self.tokenFetchLock.leave() in AWSMobileClient#releaseSignInWait()
Screenshot 2021-03-11 at 4 37 25 PM

Thanks! I've been digging this issue for two days and not having any clues yet :(

auth bug pending release

Most helpful comment

This issue should be fixed by this PR - https://github.com/aws-amplify/aws-sdk-ios/pull/3501 , pending release.

All 14 comments

After experimenting with a few different coding logics, I'm suspecting that the following flow will lead to the crash:

  1. Check isSignedIn via Amplify.Auth.fetchAuthSession() (note that isSignedIn is still true for a user with session expired)
  2. Get current user via Amplify.Auth.getCurrentUser()(note that a valid AuthUser is still returned for a user with session expired)
  3. Get user email via 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:

  1. Check isSignedIn via Amplify.Auth.fetchAuthSession() (note that isSignedIn is still true for a user with session expired)
  2. Get current user via Amplify.Auth.getCurrentUser()(note that a valid AuthUser is still returned for a user with session expired)
  3. Get user email via 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.

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:

  1. Set the refresh token to expire an hour later in Cognito console and do sign in with google.
  2. Wait an hour for token to expire, but I don't receive a .sessionExpired while still in the App. I receive one when I relaunch the App.
  3. And then I call 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?

Screen Shot 2021-04-26 at 11 13 57 PM
Screen Shot 2021-04-26 at 11 13 45 PM

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.

Was this page helpful?
0 / 5 - 0 ratings