Crash on launch. Possibly LAContext/LAClient causing the crash.

Hey, I've been trying to pinpoint what is causing this crash, but I'm having troubles understanding the Apple Crash log. I understand that this crash is happening after the app is launched, because I know we call canEvaluatePolicy() and evaluatePolicy() when the login screen finished loading. But if you notice, the following error lines after that are not related to LocalAuthentication (or so I think), therefore I'm confused.

Here's the log:

Thread 0 Crashed:
0   libsystem_platform.dylib      	0x0000000217f95fc4 _platform_strlen + 4
1   Foundation                    	0x00000001a803539c -[NSXPCEncoder _encodeInvocation:isReply:into:] + 132 (NSXPCCoder.m:456)
2   Foundation                    	0x00000001a800686c -[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:withProxy:] + 1388 (NSXPCConnection.m:1506)
3   CoreFoundation                	0x00000001a680270c ___forwarding___ + 1128 (NSForwarding.m:3618)
4   CoreFoundation                	0x00000001a6801a60 _CF_forwarding_prep_0 + 96
5   LocalAuthentication           	0x00000001dd83c6b4 __64-[LAClient evaluatePolicy:options:uiDelegate:synchronous:reply:]_block_invoke + 240 (LAClient.m:541)
6   LocalAuthentication           	0x00000001dd83bc80 __47-[LAClient _performSynchronous:callId:finally:]_block_invoke + 584 (LAClient.m:441)
7   libdispatch.dylib             	0x00000001a64d4a2c _dispatch_client_callout + 20 (object.m:560)
8   libdispatch.dylib             	0x00000001a64e42d4 _dispatch_sync_invoke_and_complete + 56 (queue.c:1028)
9   LocalAuthentication           	0x00000001dd83b9e8 -[LAClient _performSynchronous:callId:finally:] + 220 (LAClient.m:460)
10  LocalAuthentication           	0x00000001dd83c57c -[LAClient evaluatePolicy:options:uiDelegate:synchronous:reply:] + 392 (LAClient.m:540)
11  LocalAuthentication           	0x00000001dd842d48 -[LAContext _evaluatePolicy:options:log:cid:synchronous:reply:] + 472 (LAContext.m:340)
12  LocalAuthentication           	0x00000001dd838364 -[LAContext _evaluatePolicy:options:log:cid:error:] + 284 (LAContext.m:387)
13  LocalAuthentication           	0x00000001dd838090 -[LAContext canEvaluatePolicy:error:] + 304 (LAContext.m:533)
14  APIGuard                      	0x0000000101fbb144 0x101fac000 + 61764
15  APIGuard                      	0x0000000101fb99b8 0x101fac000 + 55736
16  CoreFoundation                	0x00000001a67ff324 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 28 (CFNotificationCenter.c:652)
17  CoreFoundation                	0x00000001a689bac4 ___CFXRegistrationPost_block_invoke + 52 (CFNotificationCenter.c:173)
18  CoreFoundation                	0x00000001a686ecc0 _CFXRegistrationPost + 456 (CFNotificationCenter.c:199)
19  CoreFoundation                	0x00000001a681539c _CFXNotificationPost + 728 (CFNotificationCenter.c:1147)
20  Foundation                    	0x00000001a7fdc704 -[NSNotificationCenter postNotificationName:object:userInfo:] + 96 (NSNotification.m:560)

That’s an interesting backtrace you’ve got there. Can you post the full crash report? That might yield more clues.

For info on how to do that, see Posting a Crash Report.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hey Quinn, thanks! I added the full crash file here.

Thanks for the crash report.

You wrote:

I understand that this crash is happening after the app is launched

Well, all crashes happen after the app is launched (-: but I think you meant shortly after the app is launched. That’s definitely not the case here. The app has been running for about a day:

Date/Time:           2022-04-19 11:43:05.2631 -0400
Launch Time:         2022-04-18 05:13:59.9899 -0400

I’d like to get a better handle on the specific context this crashing code is running in. Looking at your main thread I see this:

Thread 0 name:
Thread 0 Crashed:
0   libsystem_platform.dylib … _platform_strlen + 4
1   Foundation               … -[NSXPCEncoder _encodeInvocation:isReply:into:] + 132 (NSXPCCoder.m:456)
2   Foundation               … -[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:wit…
3   CoreFoundation           … ___forwarding___ + 1128 (NSForwarding.m:3618)
4   CoreFoundation           … _CF_forwarding_prep_0 + 96
5   LocalAuthentication      … __64-[LAClient evaluatePolicy:options:uiDelegate:synchronous:reply:]_block_invok…
6   LocalAuthentication      … __47-[LAClient _performSynchronous:callId:finally:]_block_invoke + 584 (LAClient…
7   libdispatch.dylib        … _dispatch_client_callout + 20 (object.m:560)
8   libdispatch.dylib        … _dispatch_sync_invoke_and_complete + 56 (queue.c:1028)
9   LocalAuthentication      … -[LAClient _performSynchronous:callId:finally:] + 220 (LAClient.m:460)
10  LocalAuthentication      … -[LAClient evaluatePolicy:options:uiDelegate:synchronous:reply:] + 392 (LAClient…
11  LocalAuthentication      … -[LAContext _evaluatePolicy:options:log:cid:synchronous:reply:] + 472 (LAContext…
12  LocalAuthentication      … -[LAContext _evaluatePolicy:options:log:cid:error:] + 284 (LAContext.m:387)
13  LocalAuthentication      … -[LAContext canEvaluatePolicy:error:] + 304 (LAContext.m:533)
14  APIGuard                 … 0x101fac000 + 61764
15  APIGuard                 … 0x101fac000 + 55736
16  CoreFoundation           … __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 28 (CFNotificationCente…

The APIGuard framework is part of your app. Is that something you built? If so, what notification is it listening for?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

APIGuard is a security framework that we use, it initializes every time application(_ application: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool is triggered. This framework is a black box, so I can't see what the initialize function is doing, but I will reach out to them and ask some questions. What makes you think that this could be the issue?

What makes you think that this could be the issue?

I’m not sure if it’s the issue but frame 14 means it’s definitely involved, in that it’s the immediate caller of -canEvaluatePolicy:error:. My next question was gonna be to ask about the details of that code, but that only makes sense if you have the source for it.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I have a similar issue, although not using APIGuard and making it slightly further in the [LAContext canEvaluatePolicy:error:] call before receiving a crash event. It's worth noting the crash is rare. I'll attach a crash report as well, but you can see the app has been running for about half a day (my logging tool shows the app crashed pretty quickly after coming back into the foreground).

For Authentication, I am using the open source library Auth0.swift Version 2.1.0. The crashing line can be found here on GitHub for context, but I don't see how it could result in a crash at this time.

Attached Crash Report

Crashed Backtrace

Thread 9 name:
Thread 9 Crashed:
0   libobjc.A.dylib               	0x000000019cff7f40 objc_msgSend + 32 (:-1)
1   libobjc.A.dylib               	0x000000019d011b24 objc_object::sidetable_release(bool, bool) + 260 (NSObject.mm:1738)
2   LocalAuthentication           	0x00000001bb288ee4 __63-[LAContext _evaluatePolicy:options:log:cid:synchronous:reply:]_block_invoke + 304 (LAContext.m:345)
3   LocalAuthentication           	0x00000001bb281ea0 __47-[LAClient _performSynchronous:callId:finally:]_block_invoke.186 + 200 (LAClient.m:449)
4   LocalAuthentication           	0x00000001bb281300 -[LAClient _checkIdResultForTCC:synchronous:error:retryBlock:finally:] + 356 (LAClient.m:401)
5   LocalAuthentication           	0x00000001bb2827b0 __64-[LAClient evaluatePolicy:options:uiDelegate:synchronous:reply:]_block_invoke_2 + 188 (LAClient.m:542)
6   CoreFoundation                	0x0000000184265b24 __invoking___ + 148 (:-1)
7   CoreFoundation                	0x0000000184283610 -[NSInvocation invoke] + 468 (NSForwarding.m:3378)
8   Foundation                    	0x0000000185a71918 __NSXPCCONNECTION_IS_CALLING_OUT_TO_REPLY_BLOCK__ + 24 (NSXPCConnection.m:170)
9   Foundation                    	0x0000000185a92f54 -[NSXPCConnection _decodeAndInvokeReplyBlockWithEvent:sequence:replyInfo:] + 572 (NSXPCConnection.m:316)
10  Foundation                    	0x0000000185a6d460 __88-[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:withProxy:]_block_invoke_3 + 212 (NSXPCConnection.m:1630)
11  Foundation                    	0x0000000185a81d4c -[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:withProxy:] + 2588 (NSXPCConnection.m:1651)
12  CoreFoundation                	0x0000000184271c1c ___forwarding___ + 1128 (NSForwarding.m:3618)
13  CoreFoundation                	0x0000000184270f70 _CF_forwarding_prep_0 + 96 (:-1)
14  LocalAuthentication           	0x00000001bb2826b4 __64-[LAClient evaluatePolicy:options:uiDelegate:synchronous:reply:]_block_invoke + 240 (LAClient.m:541)
15  LocalAuthentication           	0x00000001bb281c80 __47-[LAClient _performSynchronous:callId:finally:]_block_invoke + 584 (LAClient.m:441)
16  libdispatch.dylib             	0x0000000183f44a30 _dispatch_client_callout + 20 (object.m:560)
17  libdispatch.dylib             	0x0000000183f542d4 _dispatch_sync_invoke_and_complete + 56 (queue.c:1028)
18  LocalAuthentication           	0x00000001bb2819e8 -[LAClient _performSynchronous:callId:finally:] + 220 (LAClient.m:460)
19  LocalAuthentication           	0x00000001bb28257c -[LAClient evaluatePolicy:options:uiDelegate:synchronous:reply:] + 392 (LAClient.m:540)
20  LocalAuthentication           	0x00000001bb288d48 -[LAContext _evaluatePolicy:options:log:cid:synchronous:reply:] + 472 (LAContext.m:340)
21  LocalAuthentication           	0x00000001bb27e364 -[LAContext _evaluatePolicy:options:log:cid:error:] + 284 (LAContext.m:387)
22  LocalAuthentication           	0x00000001bb27e090 -[LAContext canEvaluatePolicy:error:] + 304 (LAContext.m:533)
23  Core                          	0x0000000103669140 available.get + 24 (BioAuthentication.swift:22)
24  Core                          	0x0000000103669140 CredentialsManager.credentials(withScope:minTTL:parameters:headers:callback:) + 104 (CredentialsManager.swift:225)
25  Core                          	0x0000000103631dd4 specialized Auth0AuthProvider.fetchTokens(onCompletion:) + 684 (<compiler-generated>:238)
26  Core                          	0x000000010362dcdc fetchTokens + 20 (AuthProvider.swift:156)
27  Core                          	0x000000010362dcdc refreshTokensIfNeeded + 20 (<compiler-generated>:0)
28  Core                          	0x000000010362dcdc refreshTokensIfNeeded + 20 (AuthInterceptor.swift:17)
29  Core                          	0x000000010362dcdc AuthInterceptor.interceptAsync<A>(chain:request:response:completion:) + 176
30  Core                          	0x000000010362dd60 protocol witness for ApolloInterceptor.interceptAsync<A>(chain:request:response:completion:) in conformance AuthInterceptor + 20 (<compiler-generated>:0)
31  Core                          	0x00000001036cecfc RequestChain.kickoff<A>(request:completion:) + 140 (RequestChain.swift:66)
32  Core                          	0x00000001036d0ce0 RequestChainNetworkTransport.send<A>(operation:cachePolicy:contextIdentifier:callbackQueue:completionHandler:) + 404 (RequestChainNetworkTransport.swift:99)
33  Core                          	0x0000000103694be8 ApolloClient.fetch<A>(query:cachePolicy:contextIdentifier:queue:resultHandler:) + 168 (ApolloClient.swift:91)
34  Core                          	0x00000001035d7c88 specialized APIClient.query<A>(_:cachePolicy:queue:resultHandler:) + 460
35  Core                          	0x00000001035d77d4 AccountHolderRepositoryImpl.loadAccountHolder(isSilent:) + 552 (AccountHolderRepository.swift:72)
36  Core                          	0x00000001035d7584 AccountHolderRepositoryImpl.refreshAccountIfNeeded(force:) + 444 (AccountHolderRepository.swift:97)

Sadly, your crash report indicates that there’s a third-party crash reporter in play, which seriously undermines my trust in it [1].

At face value, the crashing backtrace suggests a memory management issue. With regards this:

0 libobjc.A.dylib     … objc_msgSend + 32 (:-1)
1 libobjc.A.dylib     … objc_object::sidetable_release(bool, bool) + 260 (NSObject.mm:1738)
2 LocalAuthentication … __63-[LAContext _evaluatePolicy:options:log:cid:synchronous:reply:]_block_invoke + 304 (LAContext.m:345)
3 LocalAuthentication … __47-[LAClient _performSynchronous:callId:finally:]_block_invoke.186 + 200 (LAClient.m:449)

Frame 2 suggests that an object is being released by LA in frame 3 and its reference count hit 0 — remember that Objective-C stores reference counts in a side table, not in the object itself — and that trigger a -dealloc call which itself crashed.

If you’re curious about frame 2, you can see its source code in Darwin.

My usual advice when presented with a hard-to-reproduce memory management problem is to fire up the standard memory debugging tools to see if they can make the problem easier to reproduce (-:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] For an explanation as to why, see Implementing Your Own Crash Reporter.

Thanks, Quinn! I’ll look into these resources you provided soon.

Crash on launch. Possibly LAContext/LAClient causing the crash.
 
 
Q