NSKeyValuePopPendingNotificationLocal crash iOS 13 and 14

We are observing many crashes in our application related to NSKeyValuePopPendingNotificationLocal in Foundation. They appeared in the last 5 days, the Xcode version used for the build is 12.0.1 (12A7300).

Versions built with previous xcode are not affected

The stack below:



The stack below:

Please post a full Apple crash report for the problem. Using the text attachment feature (the paperclip button) to avoid clogging up the timeline.

Share and Enjoy

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



That’s not a full crash report, just a single thread’s backtrace. I’d like to get a full Apple crash report.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Code Block Crashed: NSOperationQueue 0x109f3b510 (QOS: UNSPECIFIED)
0 libobjc.A.dylib 0x1b87a8df0 objc_release + 16
1 Foundation 0x1a61df57c NSKeyValuePopPendingNotificationLocal + 60
2 Foundation 0x1a61df4f8 NSKeyValueDidChange + 356
3 Foundation 0x1a61def64 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:] + 624
4 Foundation 0x1a6123800 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 68
5 Foundation 0x1a61da3d8 _NSSetLongLongValueAndNotify + 284
6 CFNetwork 0x1a56fd074 _CFNetworkHTTPConnectionCacheSetLimit + 153068
7 Foundation 0x1a6201cc8 NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK + 16
8 Foundation 0x1a60feb18 -[NSBlockOperation main] + 100
9 Foundation 0x1a6203f80 NSOPERATION_IS_INVOKING_MAIN + 20
10 Foundation 0x1a60fe7d4 -[NSOperation start] + 784
11 Foundation 0x1a6204978 NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION + 20
12 Foundation 0x1a6204444 __NSOQSchedule_f + 180
13 libdispatch.dylib 0x1a4b4d93c _dispatch_block_async_invoke2 + 104
14 libdispatch.dylib 0x1a4b9e280 _dispatch_client_callout + 16
15 libdispatch.dylib 0x1a4b4356c _dispatch_continuation_pop$VARIANT$mp + 412
16 libdispatch.dylib 0x1a4b42cb0 _dispatch_async_redirect_invoke + 596
17 libdispatch.dylib 0x1a4b5011c _dispatch_root_queue_drain + 376
18 libdispatch.dylib 0x1a4b508e4 _dispatch_worker_thread2 + 124
19 libsystem_pthread.dylib 0x1ea848568 _pthread_wqthread + 212
20 libsystem_pthread.dylib 0x1ea84b874 start_wqthread + 8


My crash free decreased from 99% to 72% after using XCode 12 (iOS14) to compile



Same problem here.. many random crashes .



@mouness2020, In situations like this a crash report snippet is not helpful, alas. I need a full Apple crash report to make any insight into such weird problems.

@swee153, Thanks for the crash report!

Looking in that, the immediate cause of the crash is the dereference of a bogus pointer:

Code Block
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000abc1264a0


The value is way off in the weeds:

Code Block
VM Region Info: 0xabc1264a0 is not in any region. Bytes after previous region: 34830705825 Bytes before following region: 21540739936
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
MALLOC_NANO 280000000-2a0000000 [512.0M] rw-/rwx SM=PRV
---> GAP OF 0xd20000000 BYTES
commpage (reserved) fc0000000-1000000000 [ 1.0G] ---/--- SM=NUL ...(unallocated)


Looking at the crashing thread we see this:

Code Block
Thread 37 name:
Thread 37 Crashed:
0 libobjc.A.dylib … objc_release + 16 (objc-object.h:756)
1 Foundation … NSKeyValuePopPendingNotificationLocal + 60 (NSKeyValueObserving.m:1078)
2 Foundation … NSKeyValueDidChange + 356 (NSKeyValueObserving.m:533)
3 Foundation … -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:] + 624 (NSKeyValueObserving.m:2591)
4 Foundation … -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 68 (NSKeyValueObserving.m:2606)
5 Foundation … _NSSetLongLongValueAndNotify + 284 (NSKeyValueObserverNotifying.m:100)
6 CFNetwork … 51-[NSURLSession delegate_task:didCompleteWithError:]_block_invoke.194 + 60 (Session.mm:778)
7 Foundation … NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 16 (NSOperation.m:1544)


objc_release, in frame 0, is unlikely to have any bugs so we need to look deeper in the stack. Frame 1 through 5 are standard Key-Value Observing (KVO) goo. Someone is changing a property whose value is being observed by someone else. And that leads is to frame 6. Note that this includes a file name and line number, Session.mm:778. I looked that up and it’s very likely to be NSURLSession setting the state property on the task to NSURLSessionTaskStateCompleted.

There are two potential reasons for that failing:
  • A bug in KVO itself

  • Problems with whoever is observing state

I recommend that you investigate the latter first (there are plenty of bugs in KVO but there’s not much you can do about them)-: Do you you know who’s observing the state property on your tasks?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
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 combined Xcode 12. We see later today if is all fixed for our user base



Earlier I wrote:

Do you you know who’s observing the state property on your tasks?

Someone mentioned offline that this may be related to AFNetworking. That certainly rings I bell. I don’t use AFNetworking myself but I vaguely recall that it uses KVO to observe state to learn about the completion of tasks.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
@andr3a88 answer is correct. Removing Firebase/Performance fixed all the crash issues.
It was for sure a problem with Firebase Performance, it's fixed now:
https://github.com/firebase/firebase-ios-sdk/issues/6734
Our company experienced same issue. Accidentally we start to receive crashes into Firebase Crashlytics related to NSURLSession, CoreFoundation, CFDictionaryGetValue, NSKeyValuePopPendingNotificationLocal from our latest release. Previous builds has small number of similar crashes, but the last one just jumped up and dropped our crash-free users rate from 99 to 94% just in one day.
We can not publish our stack trace at public thread, so it will be reported into Feedback assistant.
I just want to confirm existence and importance of this issue.

We uploaded our last release with Xcode 12.1 (12A7403).

NSKeyValuePopPendingNotificationLocal crash iOS 13 and 14
 
 
Q