_PFObjectIDFastHash64 Crash EXC_BAD_ACCESS KERN_INVALID_ADDRESS

Since the release of iOS 14, I keep getting reports of this crash via Crashlytics and I have no idea how to figure out what is going wrong, because the stack trace doesn't touch my code anywhere. What can I do? How do I find the source of the problem?

Code Block
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000004
Crashed: com.apple.root.user-initiated-qos
0 CoreData 0x1b85a87ac _PFObjectIDFastHash64 + 40
1 CoreFoundation 0x1b254e4f8 __CFBasicHashRehash + 992
2 CoreFoundation 0x1b2552414 CFBasicHashRemoveValue + 2384
3 CoreFoundation 0x1b2469ec0 CFDictionaryRemoveValue + 236
4 CoreData 0x1b84f51c0 -[NSManagedObjectContext(_NSInternalAdditions) _forgetObject:propagateToObjectStore:removeFromRegistry:] + 124
5 CoreData 0x1b84d46ec -[_PFManagedObjectReferenceQueue _processReferenceQueue:] + 860
6 CoreData 0x1b85a0734 -[_PFAutoreleasePoolThunk dealloc] + 48
7 libobjc.A.dylib 0x1c65bb81c AutoreleasePoolPage::releaseUntil(objc_object**) + 204
8 libobjc.A.dylib 0x1c65bb6e8 objc_autoreleasePoolPop + 212
9 libdispatch.dylib 0x1b2120aa4 _dispatch_last_resort_autorelease_pool_pop + 44
10 libdispatch.dylib 0x1b21313c8 _dispatch_root_queue_drain + 1064
11 libdispatch.dylib 0x1b21318e8 _dispatch_worker_thread2 + 116
12 libsystem_pthread.dylib 0x1f9a748cc _pthread_wqthread + 216
13 libsystem_pthread.dylib 0x1f9a7b77c start_wqthread + 8

Just seconding this. We're seeing the same thing on iOS 14 devices on the version we just shipped built against the 14 SDK.
We have the same problems when we build our app with Xcode 12.0.1 (SDK 14).
Wonder if it's worth throwing together a radarr for this so it gets attention.

For what it's worth I don't see many of these so far and no repeats for users, they typically occur after a period of inactivity that could be foreground or background. Impact-wise I'm a little less concerned.
Have submitted a radar.

Adding more information in the hopes we can get a response.
  • We've got a number of other CoreData related crashes impacting the subset of our users on the new version built against the 14 SDK and running iOS 14. Trace below.

  • Other code executing at the same time is random, no consistency.

  • Timing of crash is random.

Our evaluation is that we're seeing a regression in CoreData on iOS 14.

Code Block
Crashed: NSManagedObjectContext 0x281a80410
0 CoreData 0x18919bcf4 -[NSManagedObjectContext _disposeObjects:count:notifyParent:] + 224
1 CoreData 0x189191f4c -[NSManagedObjectContext _dispose:] + 324
2 CoreData 0x18907f384 -[NSManagedObjectContext _dealloc] + 472
3 CoreData 0x1891a6b74 internalBlockToDeallocNSManagedObjectContext_block_invoke + 52
4 CoreData 0x189199b18 developerSubmittedBlockToNSManagedObjectContextPerform + 156
5 libdispatch.dylib 0x182f8b280 _dispatch_client_callout + 16
6 libdispatch.dylib 0x182f33fa8 _dispatch_lane_serial_drain$VARIANT$mp + 612
7 libdispatch.dylib 0x182f34a84 _dispatch_lane_invoke$VARIANT$mp + 424
8 libdispatch.dylib 0x182f3e518 _dispatch_workloop_worker_thread + 712
9 libsystem_pthread.dylib 0x1c7f985a4 _pthread_wqthread + 272
10 libsystem_pthread.dylib 0x1c7f9b874 start_wqthread + 8


This looks like a multi-threading bug that was previously asymptomatic. Please try the program argument (or user default) -com.apple.CoreData.ConcurrencyDebug 1

This:

Crashed: com.apple.root.user-initiated-qos
0 CoreData 0x1b85a87ac PFObjectIDFastHash64 + 40
1 CoreFoundation 0x1b254e4f8
CFBasicHashRehash + 992
2 CoreFoundation 0x1b2552414 CFBasicHashRemoveValue + 2384
3 CoreFoundation 0x1b2469ec0 CFDictionaryRemoveValue + 236
4 CoreData 0x1b84f51c0 -[NSManagedObjectContext(
NSInternalAdditions) forgetObject:propagateToObjectStore:removeFromRegistry:] + 124
5 CoreData 0x1b84d46ec -[
PFManagedObjectReferenceQueue processReferenceQueue:] + 860
6 CoreData 0x1b85a0734 -[
PFAutoreleasePoolThunk dealloc] + 48
7 libobjc.A.dylib 0x1c65bb81c AutoreleasePoolPage::releaseUntil(objcobject**) + 204
8 libobjc.A.dylib 0x1c65bb6e8 objc
autoreleasePoolPop + 212
9 libdispatch.dylib 0x1b2120aa4 dispatchlastresortautoreleasepoolpop + 44

Shows a call to executeFetchRequest or save ended up on the queue (com.apple.root.user-initiated-qos) which is NOT an NSManagedObjectContext dispatch queue. So it looks like a missing call to performBlockAndWait. Additionally, this is popping the dispatch queue's auto release pool of last resort (dispatchlastresortautoreleasepoolpop) and objects have escaped into it from the lexical scope of executeFetchRequest or save. Since performBlockAndWait and performBlock include an explicit auto release pool around their parameter's block execution, it would not be possible for a properly scoped executeFetchRequest to leak into the auto release pool of last resort.

Debugging with the flag provided by engineer above helped us quickly isolate areas of concern. This makes a lot of sense. Massive thanks for the comprehensive explanation.
This is happening to our app as well. The crash happens randomly.
Also happening on all our apps with Core Data used with multithreading. The crashes are pretty bad and the apps never recover. Was working fine before iOS 14. Here are some stacktraces for the different crashes we got so far (in production):

Crashed: NSManagedObjectContext 0x281198b60
EXCBADACCESS KERNINVALIDADDRESS 0x0000000000000004

Code Block Crashed: NSManagedObjectContext 0x281198b60
0 CoreData            0x1ac4447ac _PFObjectIDFastHash64 + 40
1 CoreFoundation         0x1a63ea4f8 CFBasicHashRehash + 992
2 CoreFoundation         0x1a63ee414 CFBasicHashRemoveValue + 2384
3 CoreFoundation         0x1a6305ec0 CFDictionaryRemoveValue + 236
4 CoreData            0x1ac3911c0 -[NSManagedObjectContext(_NSInternalAdditions) _forgetObject:propagateToObjectStore:removeFromRegistry:] + 124
5 CoreData            0x1ac3706ec -[_PFManagedObjectReferenceQueue _processReferenceQueue:] + 860
6 CoreData            0x1ac48e198 90-[NSManagedObjectContext(_NSInternalNotificationHandling) _registerAsyncReferenceCallback]_block_invoke + 72
7 CoreData            0x1ac484410 developerSubmittedBlockToNSManagedObjectContextPerform + 164
8 libdispatch.dylib       0x1a5fbcac8 _dispatch_client_callout + 20
9 libdispatch.dylib       0x1a5fc3c08 _dispatch_lane_serial_drain + 580
10 libdispatch.dylib       0x1a5fc4734 _dispatch_lane_invoke + 408
11 libdispatch.dylib       0x1a5fce528 _dispatch_workloop_worker_thread + 708
12 libsystem_pthread.dylib    0x1ed910908 _pthread_wqthread + 276
13 libsystem_pthread.dylib    0x1ed91777c start_wqthread + 8


Crashed: NSManagedObjectContext 0x281234820
EXCBADACCESS KERNINVALIDADDRESS 0x0000000000000010

Code Block Crashed: NSManagedObjectContext 0x281234820
0 CoreData            0x1ac4867ec -[NSManagedObjectContext _disposeObjects:count:notifyParent:] + 232
1 CoreData            0x1ac47c5f8 -[NSManagedObjectContext _dispose:] + 328
2 CoreData            0x1ac364360 -[NSManagedObjectContext _dealloc] + 488
3 CoreData            0x1ac4919cc internalBlockToDeallocNSManagedObjectContext_block_invoke + 56
4 CoreData            0x1ac484410 developerSubmittedBlockToNSManagedObjectContextPerform + 164
5 libdispatch.dylib       0x1a5fbcac8 _dispatch_client_callout
6 libdispatch.dylib       0x1a5fc3c08 _dispatch_lane_serial_drain
7 libdispatch.dylib       0x1a5fc4734 _dispatch_lane_invoke
8 libdispatch.dylib       0x1a5fce528 _dispatch_workloop_worker_thread
9 libsystem_pthread.dylib    0x1ed910908 _pthread_wqthread + 276
10 libsystem_pthread.dylib    0x1ed91777c start_wqthread + 8


Crashed: Local sync feed queue - syncQueue (QOS: UNSPECIFIED)
EXCBADACCESS KERNINVALIDADDRESS 0x000000014cdfc000

Code Block Crashed: Local sync feed queue - syncQueue (QOS: UNSPECIFIED)
0 CoreFoundation         0x1a63ea414 CFBasicHashRehash + 764
1 CoreFoundation         0x1a63ee414 CFBasicHashRemoveValue + 2384
2 CoreFoundation         0x1a6305ec0 CFDictionaryRemoveValue + 236
3 CoreData            0x1ac3911c0 -[NSManagedObjectContext(_NSInternalAdditions) _forgetObject:propagateToObjectStore:removeFromRegistry:] + 124
4 CoreData            0x1ac3706ec -[_PFManagedObjectReferenceQueue _processReferenceQueue:] + 860
5 CoreData            0x1ac43c734 -[_PFAutoreleasePoolThunk dealloc] + 48
6 libobjc.A.dylib        0x1ba45781c AutoreleasePoolPage::releaseUntil(objc_object**) + 204
7 libobjc.A.dylib        0x1ba4576e8 objc_autoreleasePoolPop + 212
8 Foundation           0x1a75c8fa8 -[NSOperation start] + 1320
9 Foundation           0x1a76d9624 NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION + 24
10 Foundation           0x1a76d90d0 NSOQSchedule_f + 184
11 libdispatch.dylib       0x1a5fca834 _dispatch_block_async_invoke2 + 148
12 libdispatch.dylib       0x1a5fbcac8 _dispatch_client_callout + 20
13 libdispatch.dylib       0x1a5fbfd60 _dispatch_continuation_pop + 416
14 libdispatch.dylib       0x1a5fbf494 _dispatch_async_redirect_invoke + 592
15 libdispatch.dylib       0x1a5fcd104 _dispatch_root_queue_drain + 356
16 libdispatch.dylib       0x1a5fcd8e8 _dispatch_worker_thread2 + 116
17 libsystem_pthread.dylib    0x1ed9108cc _pthread_wqthread + 216
18 libsystem_pthread.dylib    0x1ed91777c start_wqthread + 8


Crashed: NSManagedObjectContext 0x28034c340
EXCBADACCESS KERNINVALIDADDRESS 0x000000000000001c

Code Block Crashed: NSManagedObjectContext 0x28034c340
0 libobjc.A.dylib        0x1ba43a53c object_getIndexedIvars + 36
1 CoreData            0x1ac4447a8 _PFObjectIDFastHash64 + 36
2 CoreFoundation         0x1a63ea4f8 CFBasicHashRehash + 992
3 CoreFoundation         0x1a63ee414 CFBasicHashRemoveValue + 2384
4 CoreFoundation         0x1a6305ec0 CFDictionaryRemoveValue + 236
5 CoreData            0x1ac3911c0 -[NSManagedObjectContext(_NSInternalAdditions) _forgetObject:propagateToObjectStore:removeFromRegistry:] + 124
6 CoreData            0x1ac3706ec -[_PFManagedObjectReferenceQueue _processReferenceQueue:] + 860
7 CoreData            0x1ac48e198 90-[NSManagedObjectContext(_NSInternalNotificationHandling) _registerAsyncReferenceCallback]_block_invoke + 72
8 CoreData            0x1ac484410 developerSubmittedBlockToNSManagedObjectContextPerform + 164
9 libdispatch.dylib       0x1a5fbcac8 _dispatch_client_callout + 20
10 libdispatch.dylib       0x1a5fc3c08 _dispatch_lane_serial_drain + 580
11 libdispatch.dylib       0x1a5fc4734 _dispatch_lane_invoke + 408
12 libdispatch.dylib       0x1a5fce528 _dispatch_workloop_worker_thread + 708
13 libsystem_pthread.dylib    0x1ed910908 _pthread_wqthread + 276
14 libsystem_pthread.dylib    0x1ed91777c start_wqthread + 8


Here the same problem. IOS 14.. what's happen?

Is this Android quality now?
Same thing. Seems to be Xcode/SDK version related. Random Core Data related crashes starts to occur when App is compiled using Xcode 12.0-12.2 beta.

When app is compiled using Xcode 11.5 or older, app doesn't crash anymore. Runs fine also on IOS 14. Using older Xcode 11 is the current workaround.

And yeah, there are errors when app is executed with -com.apple.CoreData.ConcurrencyDebug 1 on all XCode versions. But those has been in project for ages.

It seems that something has changed on new Xcode/SDK, which makes builds more prone crashing on Core Data coding errors. Either it's not having anymore compile time magic which fixes the coding errors, or something is changed on execution/ dispatching of Core Data operations..
I also started to get a similar crash when trying to save the background context after using performAndWait.
Code Block swift
let backgroundContext = container.newBackgroundContext()
backgroundContext.performAndWait {
...
}
try backgroundContext.save()

The execution stops showing:
Code Block
    0x7fff250fb6eb <+3618>: movq   %rbx, %rdi
    0x7fff250fb6ee <+3621>: callq  0x7fff2519445a            ; _PFAssertSafeMultiThreadedAccess_impl
->  0x7fff250fb6f3 <+3626>: jmp    0x7fff250fa905            ; <+60>
    0x7fff250fb6f8 <+3631>: callq  0x7fff253bf730            ; symbol stub for: objc_exception_rethrow
    0x7fff250fb6fd <+3636>: ud2    
CoreData`+[NSManagedObjectContext Multithreading_Violation_AllThatIsLeftToUsIsHonor]:
    0x7fff25194769 <+0>: pushq  %rbp
    0x7fff2519476a <+1>: movq   %rsp, %rbp
    0x7fff2519476d <+4>: callq  0x7fff253bf78a            ; symbol stub for: objc_opt_self
->  0x7fff25194772 <+9>: ud2 


Same problem here, is the best solution to downgrade Xcode version?
Same thing. After releasing an update built with xcode 12.0.1, we started seeing the crashes.
Is there any news here about how to fix the problem?
This crash is killing me, started coming when i migrated to Xcode 12 and even on 12.1, now i have huge list of crashes just because of this. I cant even downgrade because i am using widgets. Please help if anyone finds solution to this problem
_PFObjectIDFastHash64 Crash EXC_BAD_ACCESS KERN_INVALID_ADDRESS
 
 
Q