NSKeyValuePopPendingNotificationLocal Crash on iOS 13 and 14 - ios

I am getting a crash on the live app I am working on and I can't seem to recreate or find the issue. This is the crash output:
`Crashed: NSOperationQueue 0x123e7d5c0 (QOS: UNSPECIFIED)
0 libobjc.A.dylib 0x184a52198 objc_release + 104
1 Foundation 0x1850bd930 NSKeyValuePopPendingNotificationLocal + 60
2 Foundation 0x1850bd8ac NSKeyValueDidChange.llvm.947807775919258276 + 364
3 Foundation 0x1850bd2e0 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:] + 624
4 Foundation 0x18500cb1c -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 68
5 Foundation 0x1850b8eb8 _NSSetLongLongValueAndNotify + 284
6 CFNetwork 0x1880f4470 _CFNetworkHTTPConnectionCacheSetLimit + 205660
7 Foundation 0x1850d5410 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 16
8 Foundation 0x184fdf138 -[NSBlockOperation main] + 100
9 Foundation 0x1850d7698 __NSOPERATION_IS_INVOKING_MAIN__ + 20
10 Foundation 0x184fdedd0 -[NSOperation start] + 732
11 Foundation 0x1850d8090 __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__ + 20
12 Foundation 0x1850d7b5c __NSOQSchedule_f + 180
13 libdispatch.dylib 0x18498f7dc _dispatch_block_async_invoke2 + 104
14 libdispatch.dylib 0x1849dd184 _dispatch_client_callout + 16
15 libdispatch.dylib 0x184985a3c _dispatch_continuation_pop$VARIANT$mp + 412
16 libdispatch.dylib 0x184985190 _dispatch_async_redirect_invoke + 600
17 libdispatch.dylib 0x184991fa4 _dispatch_root_queue_drain + 376
18 libdispatch.dylib 0x184992770 _dispatch_worker_thread2 + 128
19 libsystem_pthread.dylib 0x184a2cb48 _pthread_wqthread + 212
20 libsystem_pthread.dylib 0x184a2f760 start_wqthread + 8`
Please help me to figure out this thing. Thanks

It is caused by FirebasePerformance v3.3.1 and XCode 12. Use 'FirebasePerformance', '3.3.0' should solve the problem.
After setting FirebasePerformance to v3.3.0, we did not see any NSKeyValuePopPendingNotificationLocal, AFURLSessionManager, NSKVODeallocate, CFDictionaryGetValue, NSKeyValueWillChange, [NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:]... crashes anymore.
The crash-free percentage is recovered from 95% to 99.9%.

We removed Firebase Performance and since then we have not detected crashes anymore. The problem I think is due to Firebase Performance 3.3.1 with Xcode 12.

I have the same problem. My solution was to lower the version of Firebase. This problem should be caused by Firebase Performance

Related

After switching to Xcode 14 beta I got this error: QOS_CLASS_USER_INITIATED waiting on a lower QoS thread running at QOS_CLASS_DEFAULT

My app is working well and I didn't get this error on Xcode 13.4,
Is it Xcode 14 beta bug or I'm doing some bad threading?!
Thread running at QOS_CLASS_USER_INITIATED waiting on a lower QoS thread running at QOS_CLASS_DEFAULT. Investigate ways to avoid priority inversions
I didn't understand the issue, so I added my stack log too:
_TtGC7SwiftUI14_UIHostingViewVVS_P10$1dc8d4d8821BridgedNavigationView8RootView_ implements focusItemsInRect: - caching for linear focus movement is limited as long as this view is on screen.
2022-06-07 18:53:41.412342+0430 MyApp[916:25641] [UIFocus] _TtCC7SwiftUI17HostingScrollView22PlatformGroupContainer implements focusItemsInRect: - caching for linear focus movement is limited as long as this view is on screen.
Thread Performance Checker: Thread running at QOS_CLASS_USER_INITIATED waiting on a lower QoS thread running at QOS_CLASS_DEFAULT. Investigate ways to avoid priority inversionsPID: 916, TID: 25815
Backtrace
=================================================================
3 MyApp 0x0000000102c7665c -[_FSRRunLoopThread runLoop] + 44
4 MyApp 0x0000000102c763a8 __45+[NSRunLoop(FSRWebSocket) FSR_networkRunLoop]_block_invoke + 124
5 libdispatch.dylib 0x00000001054318fc _dispatch_client_callout + 16
6 libdispatch.dylib 0x0000000105433240 _dispatch_once_callout + 80
7 MyApp 0x0000000102c76304 +[NSRunLoop(FSRWebSocket) FSR_networkRunLoop] + 84
8 MyApp 0x0000000102c6ff30 -[FSRWebSocket _connect] + 68
9 MyApp 0x0000000102c6ed60 -[FSRWebSocket open] + 216
10 MyApp 0x0000000102c4ebdc -[FWebSocketConnection open] + 248
11 MyApp 0x0000000102c4d3c4 -[FConnection open] + 112
12 MyApp 0x0000000102bf1404 -[FPersistentConnection openNetworkConnectionWithContext:] + 588
13 MyApp 0x0000000102bf1078 __45-[FPersistentConnection tryScheduleReconnect]_block_invoke_2 + 332
14 MyApp 0x0000000102c3d0fc -[FIRDatabaseConnectionContextProvider fetchContextForcingRefresh:withCallback:] + 264
15 MyApp 0x0000000102bf0f0c __45-[FPersistentConnection tryScheduleReconnect]_block_invoke + 460
16 MyApp 0x0000000102c1c0d8 -[FIRRetryHelperTask execute] + 92
17 MyApp 0x0000000102c1c6dc __24-[FIRRetryHelper retry:]_block_invoke + 84
18 libdispatch.dylib 0x00000001054300c4 _dispatch_call_block_and_release + 24
19 libdispatch.dylib 0x00000001054318fc _dispatch_client_callout + 16
20 libdispatch.dylib 0x0000000105438a58 _dispatch_lane_serial_drain + 688
21 libdispatch.dylib 0x00000001054396d0 _dispatch_lane_invoke + 424
22 libdispatch.dylib 0x0000000105445150 _dispatch_workloop_worker_thread + 696
23 libsystem_pthread.dylib 0x000000023db94ddc _pthread_wqthread + 284
24 libsystem_pthread.dylib 0x000000023db94908 start_wqthread + 8
You're getting this message due to a priority inversion in your code. More details here: https://developer.apple.com/documentation/xcode/diagnosing-performance-issues-early
More specifically, you're using dispatch_group_wait which doesn't provide priority inversion avoidance; so your waiting thread is susceptible to an inversion. Seemingly that's what's happening here.

Crash on Error Code: -1001 Error: NSURLErrorTimedOut

I am having the following crash (0.05% crash rate, so I have yet to reproduce it):
0 libdispatch.dylib 0x208b2028 _dispatch_semaphore_signal_slow + 174
! 1 MyProject 0x00253f39 __64-[CRNSURLSessionTaskProxy wrapDataCompletionHandler:forSession:]_block_invoke + 422
2 CFNetwork 0x2120796d __75-[__NSURLSessionLocal taskForClass:request:uploadFile:bodyData:completion:]_block_invoke + 14
3 CFNetwork 0x21216ef7 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 276
4 Foundation 0x2150a52d __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 6
5 Foundation 0x2146beff -[NSBlockOperation main] + 144
6 Foundation 0x2145e2ef -[__NSOperationInternal _start:] + 772
7 Foundation 0x2150c7ed __NSOQSchedule_f + 190
8 libdispatch.dylib 0x208adf97 _dispatch_queue_drain + 1760
9 libdispatch.dylib 0x208a6f2f _dispatch_queue_invoke + 280
10 libdispatch.dylib 0x208af325 _dispatch_root_queue_drain + 398
11 libdispatch.dylib 0x208af193 _dispatch_worker_thread3 + 92
12 libsystem_pthread.dylib 0x20a3ce0d _pthread_wqthread + 1022
13 libsystem_pthread.dylib 0x20a3c9fc start_wqthread + 6
The crashes only appears on iOS9, none whatsoever on iOS8, but this could just be a coincidence. I am also seeing this via Crittercism breadcrumbs:
I am also using Background Fetches which do hit the network layer.
Any idea why this is happing?
This looks to me like a bug with Crittercism. The class CRNSURLSessionTaskProxy is a Crittercism class (see below), so it's crashing in their code, which is corroborated by the errors in the Crittercism breadcrumbs.
The only Google hit (other than this question) for the class name is this one. If you look at the other classes in that dump that start with CR, you will see CRBreadcrumbs and CRCrash.
Also here's a dump of the Crittercism framework in the Hopper disassembler:
Pretty conclusive I would say.

FMDBBlockSQLiteCallBackFunction Crash in app that's not using makeFunctionNamed

I'm working on an app that's in the app store, which uses FMDB for interacting with its sqlite database. We've received some crash reports with stack traces like this:
Thread : Crashed: NSOperationQueue 0x170239c20 :: NSOperation 0x17024d7d0 (QOS: LEGACY)
0 libobjc.A.dylib 0x000000019701c0b4 objc_retain + 20
1 MyApp 0x00000001002bdff4 FMDBBlockSQLiteCallBackFunction
2 MyApp 0x00000001002bdb1c FMDBBlockSQLiteCallBackFunction
3 MyApp 0x00000001002b66b4 FMDBBlockSQLiteCallBackFunction
4 MyApp 0x00000001002980fc FMDBBlockSQLiteCallBackFunction
5 MyApp 0x000000010029f20c FMDBBlockSQLiteCallBackFunction
6 CFNetwork 0x00000001851475a4 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 300
7 Foundation 0x00000001866bf1c4 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 16
8 Foundation 0x0000000186610604 -[NSBlockOperation main] + 96
9 Foundation 0x00000001866001cc -[__NSOperationInternal _start:] + 636
10 Foundation 0x00000001866c1f28 __NSOQSchedule_f + 228
11 libdispatch.dylib 0x0000000197655954 _dispatch_client_callout + 16
12 libdispatch.dylib 0x00000001976600a4 _dispatch_queue_drain + 1448
13 libdispatch.dylib 0x0000000197658a5c _dispatch_queue_invoke + 132
14 libdispatch.dylib 0x0000000197662318 _dispatch_root_queue_drain + 720
15 libdispatch.dylib 0x0000000197663c4c _dispatch_worker_thread3 + 108
16 libsystem_pthread.dylib 0x000000019783522c _pthread_wqthread + 816
However, from reading the FMDB code it looks like FMDBBlockSQLiteCallBackFunction is only called as the callback for SQLite functions created using FMDatabase's makeFunctionNamed:maximumArguments:withBlock: method, which we're not using at all.
Any ideas what could be causing crashes like this?
The didFinish makes it look like you may have a race condition on this line:
6 CFNetwork 0x00000001851475a4 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 300
Try to emulate slow hardware to reproduce the end user’s state.

iOS app crashing in release but not in development and Swift symbols are not resolved

My app is working perfectly fine in development but switching to production / AdHoc release it crashes on the transition to the third UIViewController of my application flow.
Between the build there shouldn't be any difference. I have retrieved the log from the Devices window:
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x00000001000d49ac
Triggered by Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 MYAPP 0x00000001000d49ac 0x100010000 + 805292
1 UIKit 0x00000001868a8954 -[UIViewController loadViewIfRequired] + 688
2 UIKit 0x00000001868a8664 -[UIViewController view] + 28
3 UIKit 0x0000000186f9c1cc -[_UIFullscreenPresentationController _setPresentedViewController:] + 72
4 UIKit 0x0000000186ba378c -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 116
5 UIKit 0x0000000186bbeb4c -[UIViewController _presentViewController:withAnimationController:completion:] + 1968
6 UIKit 0x0000000186bc0f64 __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 116
7 UIKit 0x0000000186995c48 -[UIViewController presentViewController:animated:completion:] + 212
8 MYAPP 0x0000000100090dcc 0x100010000 + 527820
9 MYAPP 0x0000000100090bd0 0x100010000 + 527312
10 PromiseKit 0x000000010032a9f4 0x1002e8000 + 272884
11 PromiseKit 0x00000001002ee820 0x1002e8000 + 26656
12 libdispatch.dylib 0x00000001936c1990 _dispatch_call_block_and_release + 20
13 libdispatch.dylib 0x00000001936c1950 _dispatch_client_callout + 12
14 libdispatch.dylib 0x00000001936c6208 _dispatch_main_queue_callback_4CF + 1604
15 CoreFoundation 0x00000001820522e8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
16 CoreFoundation 0x0000000182050390 __CFRunLoopRun + 1488
17 CoreFoundation 0x0000000181f7d1f0 CFRunLoopRunSpecific + 392
18 GraphicsServices 0x000000018b39f6f8 GSEventRunModal + 164
19 UIKit 0x000000018690e108 UIApplicationMain + 1484
20 MYAPP 0x00000001000be820 0x100010000 + 714784
21 libdyld.dylib 0x00000001936eea04 start + 0
What is bugging me:
There is a clear inconsistency between the environments I am working on.
The calls from MYAPP doesn't seem to be linked to any component / method call. I'm working with Swift maybe it does cause problem to resolve symbols. Which could make sense since PromiseKit calls are also unresolved.
I have no idea about how to debug this, not even about how to put log everywhere (because I wouldn't know how to get them).
Any help is welcome!
In Build settings, try changing Swift compiler -> Optimization Level -> Release to None. There's still a bug where sometimes the compiler messes up closures when optimizations are on. Maybe that's what's happening to you.

iOS: Need help figuring out this crash "Crashed: NSOperationQueue Serial Queue EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x00000000"

This is the crash report I received from crashlytics and I don't have the slightest clue on what it means or what to do about this. Any tips or suggestions will be appreciated.
Thread : Crashed: NSOperationQueue Serial Queue
0 libsystem_platform.dylib 0x3baef4da _platform_memmove$VARIANT$Swift + 185
1 ??? 0x0000000c
2 DataDetectorsCore 0x350b26bb DDTokenCacheGetItemAtIndexCreateIfNeeded + 90
3 DataDetectorsCore 0x350b2635 DDTokenCacheGetTokensAtPosition + 1084
4 DataDetectorsCore 0x350ae41d _DDScannerHandleState + 472
5 DataDetectorsCore 0x350aea71 _DDScannerHandleState + 2092
6 DataDetectorsCore 0x350addf1 DDScannerScanQuery + 328
7 DataDetectorsUI 0x350c8f7d -[DDOperation main] + 288
8 Foundation 0x31664aa5 -[__NSOperationInternal _start:] + 772
9 Foundation 0x3170896d __NSOQSchedule_f + 60
10 libdispatch.dylib 0x3b9c5e7b _dispatch_queue_drain + 374
11 libdispatch.dylib 0x3b9c2f93 _dispatch_queue_invoke + 42
12 libdispatch.dylib 0x3b9c6745 _dispatch_root_queue_drain + 76
13 libdispatch.dylib 0x3b9c69c5 _dispatch_worker_thread2 + 56
14 libsystem_pthread.dylib 0x3baf0dff _pthread_wqthread + 298
Do you have any part of your app where the user clicks on a URL or specifies a URL which is then handled by your app, or by the system on behalf of your app. The subsystem that does this is DataDetectorsCore.
If you have code around that area, it would be a good idea to add log messages, assert checks, validation, and unit test code.
It might be that you are receiving maliciously crafted URLs; here is an example but for the Mac platform: http://nakedsecurity.sophos.com/2013/02/06/anatomy-of-a-bug-how-mac-os-x-chokes-if-you-type-file/

Resources