AWSMobileClient Crash when app starts
We had one occurrence of our app crashing on startup that relates to AWSMobileClient. Unfortunately we only have limited information at this time with the following stack trace:
- Crashed: com.apple.root.default-qos
- 0 AWSMobileClient 0x2e2b8 $sSlsSQ7ElementRpzrlE10firstIndex2of0C0QzSgAB_tFSay15AWSMobileClient28FetchUserPoolTokensOperationCG_Tg5 + 280
- 1 AWSMobileClient 0x2e0a8 $s15AWSMobileClientAAC9getTokensyyyAA0D0VSg_s5Error_pSgtcFyycfU_ + 140
- 2 AWSMobileClient 0x2e00c $sIeg_IeyB_TR + 28
- 3 Foundation 0x9901c __111+[__NSOperationInternalObserver _observeValueForKeyPath:ofObject:changeKind:oldValue:newValue:indexes:context:]_block_invoke_2 + 36
- 4 libdispatch.dylib 0x1e68 _dispatch_call_block_and_release + 32
- 5 libdispatch.dylib 0x3a2c _dispatch_client_callout + 20
- 6 libdispatch.dylib 0x6b44 _dispatch_queue_override_invoke + 784
- 7 libdispatch.dylib 0x15164 _dispatch_root_queue_drain + 396
- 8 libdispatch.dylib 0x1596c _dispatch_worker_thread2 + 164
- 9 libsystem_pthread.dylib 0x1080 _pthread_wqthread + 228
- 10 libsystem_pthread.dylib 0xe5c start_wqthread + 8
Currently unable to reproduce.
Environment:
- AppSync SDK Version: 3.6.0
- Dependency Manager: Cocoapods
- Swift Version : 5.0
Device Information:
- Device: iPhone 12
- iOS Version: iOS 15.4.1
- Specific to simulators: no
Thanks for reporting this. Can you provide some additional details such as your config with sensitive information removed and the code snippet you're using to initialize the AppSync client? Without the ability to reproduce this issue, this will be difficult to diagnose.
@ameter Thanks for your reply.
Here is our configuration code:
["UserAgent": "aws-amplify/cli",
"Version": "0.1.0",
"IdentityManager": ["Default": [:]],
"AppSync": [
"Default": [
"ApiUrl": apiUrl,
"Region": "aws-region",
"AuthMode": "AMAZON_COGNITO_USER_POOLS",
"ClientDatabasePrefix": "Application_AMAZON_COGNITO_USER_POOLS"
]
],
"CredentialsProvider": [
"CognitoIdentity": [
"Default": [:]
]
],
"CognitoUserPool": [
"Default": [
"PoolId": poolId,
"AppClientId": appClientId,
"AppClientSecret": appClientSecret,
"Region": "aws-region"
]
],
"Auth": [
"Default": ["authenticationFlowType": "USER_SRP_AUTH"]
]
]
As for our initialization code, here's a draft of how we initialize the client:
public final class MobileClient {
private var mobileClient: AWSMobileClient?
private var appSyncClient: AWSAppSyncClient?
func getMobileClient() -> AWSMobileClient? {
let client = AWSMobileClient(configuration: configuration)
client.initialize { [weak self] userState, error in
if let error = error {
return nil
}
guard self?.appSyncInit(cognitoUserPoolsAuthProvider: client) == true else {
return nil
}
do {
appSyncClient = try AWSAppSyncClient(cognitoUserPoolsAuthProvider: client)
} catch {
return nil
}
DispatchQueue.main.async {
client.addUserStateListener(self) { userState, _ in
switch userState {
case .guest:
//print log
case .signedOut:
//print log
case .signedIn:
//print log
case .signedOutUserPoolsTokenInvalid:
//print log
self.signOut { error in
if let error = error {
//print log
}
}
case .signedOutFederatedTokensInvalid:
//print log
default:
//print log
}
}
}
}
}
mobileClient = client
return client
}
Please let m know if there are any more information I can provide.
Can you please provide the full crash report? Thanks!