Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash: "SWIFT TASK CONTINUATION MISUSE" in ShowHostedUISign[In/Out].execute #3362

Closed
maxchuquimia opened this issue Nov 13, 2023 · 15 comments
Closed
Assignees
Labels
auth Issues related to the Auth category bug Something isn't working

Comments

@maxchuquimia
Copy link

Describe the bug

We are receiving numerous crash logs in production related to the Amplify hosted UI. We are unable to reproduce the issue, however we believe it is similar to an Auth0 issue (see Steps To Reproduce).

_Concurrency/CheckedContinuation.swift > Fatal error > SWIFT TASK CONTINUATION MISUSE: execute(withDispatcher:environment:) tried to resume its continuation more than once, throwing cancelled!
OS Version: iOS 16.1.2 (20B110)
Report Version: 104

Exception Type: EXC_BREAKPOINT (SIGTRAP)
Crashed Thread: 0

Application Specific Information:
_Concurrency/CheckedContinuation.swift > Fatal error

Thread 0 Crashed:
0   libswiftCore.dylib              0x30cc81d7c         _assertionFailure
1   libswift_Concurrency.dylib      0x32d69d55c         CheckedContinuation.resume
2   App                             0x1058f36bc         [inlined] CheckedContinuation.resume<T>
3   App                             0x1058f36bc         ShowHostedUISignIn.execute (ShowHostedUISignIn.swift:59)
4   App                             0x105b00d4c         HostedUIASWebAuthenticationSession.showHostedUI (HostedUIASWebAuthenticationSession.swift:43)
5   App                             0x105b0192c         thunk for closure
6   AuthenticationServices          0x3e26b5540         <redacted>
7   SafariServices                  0x3525b43bc         <redacted>
8   SafariServices                  0x352663020         <redacted>
9   SafariServices                  0x35263b2f4         <redacted>
10  CoreFoundation                  0x31901c700         __invoking___
11  CoreFoundation                  0x318fc8b68         -[NSInvocation invoke]
12  libdispatch.dylib               0x327b57fd8         _dispatch_client_callout
13  libdispatch.dylib               0x327b5ba58         _dispatch_block_invoke_direct
14  FrontBoardServices              0x3448053ac         __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__
15  FrontBoardServices              0x344804f48         -[FBSSerialQueue _targetQueue_performNextIfPossible]
16  FrontBoardServices              0x344807728         -[FBSSerialQueue _performNextFromRunLoopSource]
17  CoreFoundation                  0x31907df50         __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
18  CoreFoundation                  0x31908a328         __CFRunLoopDoSource0
19  CoreFoundation                  0x31900e20c         __CFRunLoopDoSources0
20  CoreFoundation                  0x319023ba4         __CFRunLoopRun
21  CoreFoundation                  0x319028ed0         CFRunLoopRunSpecific
22  GraphicsServices                0x38b6ab364         GSEventRunModal
23  UIKitCore                       0x31d6c43cc         -[UIApplication _run]
24  UIKitCore                       0x31d6c4030         UIApplicationMain
25  SwiftUI                         0x3204af010         OUTLINED_FUNCTION_895
26  SwiftUI                         0x320410168         block_copy_helper.1
27  SwiftUI                         0x3203f94b8         OUTLINED_FUNCTION_901
28  <redacted>                      0x202da44e0         [inlined] <redacted>App.$main
29  <redacted>                      0x202da44e0         main
30  <unknown>                       0x1b0908960         <redacted>

Note that we are using async/await APIs in our app to interact with Amplify Swift.

Steps To Reproduce

We are unable to reproduce the issue, however we believe it may be similar to an issue discovered in the Auth0 SDK:

https://github.com/auth0/Auth0.swift/issues/729

Expected behavior

The CheckedContinuation instance in the ShowHostedUISignIn.execute and ShowHostedUISignOut.execute functions should not be resumed twice. This may be a bug in ASWebAuthenticationSession, however it is causing production crashes so may need to be worked around within the Amplify Swift SDK.

Amplify Framework Version

2.21.3 and previous versions

Amplify Categories

Auth

Dependency manager

Swift PM

Swift version

5.7

CLI version

None

Xcode version

15.0.1 (15A507)

Relevant log output

No response

Is this a regression?

No

Regression additional context

No response

Platforms

iOS

OS Version

iOS16+ and iOS17+

Device

Various iOS devices

Specific to simulators

No response

Additional context

No response

@lawmicha lawmicha added bug Something isn't working auth Issues related to the Auth category labels Nov 13, 2023
@lawmicha
Copy link
Member

Thanks for opening this issue.

The team will investigate and get back to you as soon as we have more information.

@harsh62
Copy link
Member

harsh62 commented Nov 15, 2023

@maxchuquimia I have been unable to recreate this issue in my local environment. I have also gone through the Auth0 issue that have been attached, and I guess its fundamentally a little different as Auth0 seems to be caching certain requests. In Amplify's case, there is no caching happening and hence the continuations are not reused. Every request creates a new one and the old one is discarded.

It would be nice if you can try to recreate this issue and share steps, or provide insights from your users behaviours that could provide in debugging the issue further.

@maxchuquimia
Copy link
Author

maxchuquimia commented Nov 15, 2023

Thanks @harsh62 -- We are continuing to try and reproduce the issue but have had no success. We can tell from logs that the crash correlates with the device returning to the foreground during authentication (as described in the Auth0 issue via the Control Centre).

Despite being unable to reproduce the issue, calling a continuation twice is not supported behavior for concurrency (even if it is indeed some strange ASWebAuthenticationSession double-callback issue causing it to be resumed twice).

@harsh62
Copy link
Member

harsh62 commented Nov 16, 2023

@maxchuquimia Thanks for reverting back. Would you be able to share a symbolicated crash log that you are seeing. There might be something in the crash log that could give us hint on what the problem could be.

@maxchuquimia
Copy link
Author

Hey @harsh62, please find two attached examples (one for signing in and one for signing out). In the traces RedactedApp refers to our Xcode project and App refers to our Swift Package that contains all our project's code.

crashes.zip

@harsh62
Copy link
Member

harsh62 commented Nov 17, 2023

@maxchuquimia Thanks for providing the information. Could you also share the code snippet and surrounding code that is used to call the Amplify.Auth API?

@maxchuquimia
Copy link
Author

Hey @harsh62, here's how we use it:

func login(with socialAuth: SocialAuth) async throws {
    let result: AuthSignInResult

    do {
        switch socialAuth {
        case .google:
            result = try await Amplify.Auth.signInWithWebUI(for: .google, options:  authOptions.cognitoOptions(provider: .google))
            if result.isSignedIn {
                authOptions.setLogInCompleted(provider: .google)
            }
        case .microsoft:
            result = try await Amplify.Auth.signInWithWebUI(for: .oidc("Microsoft"), options: authOptions.cognitoOptions(provider: .microsoft))
            if result.isSignedIn {
                authOptions.setLogInCompleted(provider: .microsoft)
            }
        case .apple:
            result = try await Amplify.Auth.signInWithWebUI(for: .apple, options: authOptions.cognitoOptions(provider: .apple))
            if result.isSignedIn {
                authOptions.setLogInCompleted(provider: .apple)
            }
        }
    } catch {
        throw AppAuthError(cognitoError: error) ?? error
    }

    _isLoggedInPublisher.send(result.isSignedIn)
}

@harsh62
Copy link
Member

harsh62 commented Nov 20, 2023

@maxchuquimia Thanks for providing more details.. I am still not able to get this crash locally..

Nevertheless, I have made a small fix in #3363 .. Is it possible if you can test the branch in the PR (fix/hosted-ui-crash) and let me know if it resolves the issue.

@maxchuquimia
Copy link
Author

@harsh62 Thanks for your time on this! I have tried again for a long time this morning to reproduce the crash but still cannot. I also briefly tested your PR branch locally and it didn't seems to cause any new issues.

Not sure what the best way forward is now, perhaps we need to release and then see if the crashes stop?

@harsh62 harsh62 self-assigned this Nov 21, 2023
@harsh62
Copy link
Member

harsh62 commented Nov 21, 2023

@maxchuquimia I will work on drafting a release. Amplify is due to release sometime later next week. I will post an update on the issue when that happens.

@5d
Copy link
Member

5d commented Dec 8, 2023

The issue ticket is now closed as the fix has been released in the latest version 2.25.0. If you continue to encounter the problem, please don't hesitate to reopen the ticket.

@5d 5d closed this as completed Dec 8, 2023
@maxchuquimia
Copy link
Author

Unfortunately this is still occurring after upgrading to Amplify Swift 2.25.0 - here are three examples...

51e7adc05d19491b8f25fd7b1f0410fb-symbolicated.crash.txt
835f3e8ede8e45b3b7d1882d88fc8fe0-symbolicated.crash.txt
2ab84b6008594af099167787fc942387-symbolicated.crash.txt

@lawmicha lawmicha reopened this Dec 29, 2023
@atierian
Copy link
Member

atierian commented Jan 9, 2024

Thanks for letting us know and for the crash logs. We're investigating and will provide an update when we can.

@harsh62
Copy link
Member

harsh62 commented Jan 15, 2024

@maxchuquimia We've released a new version (2.25.4) with the potential fix.
Please reopen the issue if you have more questions. Thanks for your patience.

@harsh62 harsh62 closed this as completed Jan 15, 2024
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth Issues related to the Auth category bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants