Describe the bug
App crashes within AWSAuthCore intermittently, presumably at AWSIdentityManager.m:80 while trying to create a dictionary.
An exception message is:
Fatal Exception: NSInvalidArgumentException
*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
To Reproduce
Crash is intermittent, I grab it from users' crash logs, an example stack trace:
Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x23ba68ec4 __exceptionPreprocess
1 libobjc.A.dylib 0x23ac39a50 objc_exception_throw
2 CoreFoundation 0x23b9e0494 _CFArgv
3 CoreFoundation 0x23b966980 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]
4 CoreFoundation 0x23b9574c4 +[NSDictionary dictionaryWithObjects:forKeys:count:]
5 AWSAuthCore 0x1049a3b40 (Missing)
6 AWSCore 0x104eb36e8 (Missing)
7 AWSCore 0x104eb3058 (Missing)
8 AWSCore 0x104e804ac (Missing)
9 AWSCore 0x104e80a18 (Missing)
10 AWSCore 0x104eb2c50 (Missing)
11 AWSCore 0x104eb2788 (Missing)
12 AWSCore 0x104eb3dd4 (Missing)
13 AWSCore 0x104eb312c (Missing)
14 Foundation 0x23c4f88bc __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__
15 Foundation 0x23c400ab8 -[NSBlockOperation main]
16 Foundation 0x23c3fff8c -[__NSOperationInternal _start:]
17 Foundation 0x23c4fa790 __NSOQSchedule_f
18 libdispatch.dylib 0x23b4a16c8 _dispatch_call_block_and_release
19 libdispatch.dylib 0x23b4a2484 _dispatch_client_callout
20 libdispatch.dylib 0x23b44582c _dispatch_continuation_pop$VARIANT$mp
21 libdispatch.dylib 0x23b444ef4 _dispatch_async_redirect_invoke
22 libdispatch.dylib 0x23b451a18 _dispatch_root_queue_drain
23 libdispatch.dylib 0x23b4522c0 _dispatch_worker_thread2
24 libsystem_pthread.dylib 0x23b68517c _pthread_wqthread
25 libsystem_pthread.dylib 0x23b687cec start_wqthread
Which AWS service(s) are affected?
AWSAuthCore
Expected behavior
No crash
Screenshots
No screenhots
Environment(please complete the following information):
Device Information (please complete the following information):
Additional context
It always happens on a background thread. There's also always the same operation on a main thread at the time of the crash:
com.apple.main-thread
0 libsystem_kernel.dylib 0x20df93ea4 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x20df9337c mach_msg + 72
2 libdispatch.dylib 0x20ddf82d0 _dispatch_mach_send_and_wait_for_reply + 500
3 libdispatch.dylib 0x20ddf8764 dispatch_mach_send_with_result_and_wait_for_reply$VARIANT$mp + 56
4 libxpc.dylib 0x20e05beb4 xpc_connection_send_message_with_reply_sync + 204
5 Security 0x20f0adaac securityd_message_with_reply_sync + 96
6 Security 0x20f0ae070 securityd_send_sync_and_do + 80
7 Security 0x20f107a84 __SecItemCopyMatching_block_invoke_2 + 240
8 Security 0x20f1068c4 __SecItemAuthDoQuery_block_invoke + 312
9 Security 0x20f105314 SecItemAuthDo + 108
10 Security 0x20f105bac SecItemAuthDoQuery + 512
11 Security 0x20f10796c __SecItemCopyMatching_block_invoke + 120
12 Security 0x20f103920 SecOSStatusWith + 52
13 Security 0x20f105fa0 SecItemCopyMatching + 332
14 AWSCore 0x1033e7604 -[AWSUICKeyChainStore dataForKey:error:] + 208
15 AWSCore 0x1033e6ed8 -[AWSUICKeyChainStore stringForKey:error:] + 40
16 AWSCore 0x10338f18c -[AWSCognitoCredentialsProvider internalCredentials] + 116
17 AWSCore 0x10338ddb4 -[AWSCognitoCredentialsProvider credentials] + 52
18 AWSAuthCore 0x102ea0734 -[AWSSignInManager completeLogin] + 244
19 AWSGoogleSignIn 0x103039450 -[AWSGoogleSignInProvider completeLoginWithToken] + 56
20 AWSGoogleSignIn 0x103039734 -[AWSGoogleSignInProvider signIn:didSignInForUser:withError:] + 576
21 MyApp 0x102d3fb7c __31-[GIDSignIn signInWithOptions:]_block_invoke + 4332698492
22 MyApp 0x102d36548 -[GIDAuthentication getTokensWithHandler:] + 4332660040
23 MyApp 0x102d3faa8 -[GIDSignIn signInWithOptions:] + 4332698280
24 MyApp 0x102d3c0a8 -[GIDSignIn signInSilently] + 4332683432
25 AWSGoogleSignIn 0x103039338 __32-[AWSGoogleSignInProvider token]_block_invoke_2 + 52
26 libdispatch.dylib 0x20de416c8 _dispatch_call_block_and_release + 24
27 libdispatch.dylib 0x20de42484 _dispatch_client_callout + 16
28 libdispatch.dylib 0x20ddee9a4 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1068
29 CoreFoundation 0x20e398df4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
30 CoreFoundation 0x20e393cbc __CFRunLoopRun + 1964
31 CoreFoundation 0x20e3931f0 CFRunLoopRunSpecific + 436
32 GraphicsServices 0x21060c584 GSEventRunModal + 100
33 UIKitCore 0x23b6ead40 UIApplicationMain + 212
34 MyApp 0x102c4dc8c main (AppDelegate.swift:25)
35 libdyld.dylib 0x20de52bb4 start + 4
I derive that this is some multithreading issue, when task.result is nil in continueWithSuccessBlock: within [AWSIdentityManager logins] at line 79 and further it crashes while creating dictionary at line 80.
P.S. I studied other issues before opening this, https://github.com/aws-amplify/aws-sdk-ios/issues/1060 is similar, but not related. Please don't refer to it as a possible duplicate.
Hello @soxjke
Thanks for reporting this. I agree with your analysis that it is likely due to task.result which has the auth token is nil.
Could you please describe what API/ functionality in auth core you are using? This will help me start tracking the code path for this crash. A simple fix would be a null check, but I want to be sure to identify a root cause and fix it.
Thanks,
Rohan
Hi @rohandubal
The list functionality used by the app:
AWSIdentityManager.default().logins()AWSIdentityManager.default().identityIdAWSSignInManager.sharedInstance().resumeSessionAWSSignInManager.sharedInstance().logoutAWSSignInManager.sharedInstance().interceptApplication AWSFacebookSignInProvider.sharedInstance().setPermissions(["public_profile"])
AWSSignInManager.sharedInstance().register(signInProvider: AWSFacebookSignInProvider.sharedInstance())
AWSGoogleSignInProvider.sharedInstance().setScopes(["profile", "openid"])
AWSSignInManager.sharedInstance().register(signInProvider: AWSGoogleSignInProvider.sharedInstance())
AWSSignInManager.sharedInstance().register(signInProvider: AWSCognitoUserPoolsSignInProvider.sharedInstance())
However, I'd try to focus on following tips:
-[GIDSignIn signInSilently] call at AWSGoogleSignInProvider.m:156 on the main thread, while the background thread is crashed on a mentioned stacktrace.result at AWSGoogleSignInProvider.m:156 triggers the success block in AWSIdentityManager, so the crash comes from GoogleSignIn, where token is returned nil from Google lib in -signIn:didSignInForUser:withError:while error is also nilI am facing the same problem now. Any suggestion to fix this?
Same problem here. Have anyone been able to fix this?
The main idea of fix is basically to to add check for nil at AWSIdentityManager.m:78
You can fork and do a fix or use runtime to apply workaround. My choice for now is runtime - here's gist
https://gist.github.com/soxjke/4c79e923ec549e8d7e4e0ef219f12bd5
@soulchain @pablogeek
Most helpful comment
I am facing the same problem now. Any suggestion to fix this?