_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 0x0000000000000004Crashed: com.apple.root.user-initiated-qos0  CoreData                       0x1b85a87ac _PFObjectIDFastHash64 + 401  CoreFoundation                 0x1b254e4f8 __CFBasicHashRehash + 9922  CoreFoundation                 0x1b2552414 CFBasicHashRemoveValue + 23843  CoreFoundation                 0x1b2469ec0 CFDictionaryRemoveValue + 2364  CoreData                       0x1b84f51c0 -[NSManagedObjectContext(_NSInternalAdditions) _forgetObject:propagateToObjectStore:removeFromRegistry:] + 1245  CoreData                       0x1b84d46ec -[_PFManagedObjectReferenceQueue _processReferenceQueue:] + 8606  CoreData                       0x1b85a0734 -[_PFAutoreleasePoolThunk dealloc] + 487  libobjc.A.dylib                0x1c65bb81c AutoreleasePoolPage::releaseUntil(objc_object**) + 2048  libobjc.A.dylib                0x1c65bb6e8 objc_autoreleasePoolPop + 2129  libdispatch.dylib              0x1b2120aa4 _dispatch_last_resort_autorelease_pool_pop + 4410 libdispatch.dylib              0x1b21313c8 _dispatch_root_queue_drain + 106411 libdispatch.dylib              0x1b21318e8 _dispatch_worker_thread2 + 11612 libsystem_pthread.dylib        0x1f9a748cc _pthread_wqthread + 21613 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 0x281a804100  CoreData                       0x18919bcf4 -[NSManagedObjectContext _disposeObjects:count:notifyParent:] + 2241  CoreData                       0x189191f4c -[NSManagedObjectContext _dispose:] + 3242  CoreData                       0x18907f384 -[NSManagedObjectContext _dealloc] + 4723  CoreData                       0x1891a6b74 internalBlockToDeallocNSManagedObjectContext_block_invoke + 524  CoreData                       0x189199b18 developerSubmittedBlockToNSManagedObjectContextPerform + 1565  libdispatch.dylib              0x182f8b280 _dispatch_client_callout + 166  libdispatch.dylib              0x182f33fa8 _dispatch_lane_serial_drain$VARIANT$mp + 6127  libdispatch.dylib              0x182f34a84 _dispatch_lane_invoke$VARIANT$mp + 4248  libdispatch.dylib              0x182f3e518 _dispatch_workloop_worker_thread + 7129  libsystem_pthread.dylib        0x1c7f985a4 _pthread_wqthread + 27210 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.
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 0x281198b600 CoreData            0x1ac4447ac _PFObjectIDFastHash64 + 401 CoreFoundation         0x1a63ea4f8 CFBasicHashRehash + 9922 CoreFoundation         0x1a63ee414 CFBasicHashRemoveValue + 23843 CoreFoundation         0x1a6305ec0 CFDictionaryRemoveValue + 2364 CoreData            0x1ac3911c0 -[NSManagedObjectContext(_NSInternalAdditions) _forgetObject:propagateToObjectStore:removeFromRegistry:] + 1245 CoreData            0x1ac3706ec -[_PFManagedObjectReferenceQueue _processReferenceQueue:] + 8606 CoreData            0x1ac48e198 90-[NSManagedObjectContext(_NSInternalNotificationHandling) _registerAsyncReferenceCallback]_block_invoke + 727 CoreData            0x1ac484410 developerSubmittedBlockToNSManagedObjectContextPerform + 1648 libdispatch.dylib       0x1a5fbcac8 _dispatch_client_callout + 209 libdispatch.dylib       0x1a5fc3c08 _dispatch_lane_serial_drain + 58010 libdispatch.dylib       0x1a5fc4734 _dispatch_lane_invoke + 40811 libdispatch.dylib       0x1a5fce528 _dispatch_workloop_worker_thread + 70812 libsystem_pthread.dylib    0x1ed910908 _pthread_wqthread + 27613 libsystem_pthread.dylib    0x1ed91777c start_wqthread + 8


Crashed: NSManagedObjectContext 0x281234820
EXCBADACCESS KERNINVALIDADDRESS 0x0000000000000010

Code Block Crashed: NSManagedObjectContext 0x2812348200 CoreData            0x1ac4867ec -[NSManagedObjectContext _disposeObjects:count:notifyParent:] + 2321 CoreData            0x1ac47c5f8 -[NSManagedObjectContext _dispose:] + 3282 CoreData            0x1ac364360 -[NSManagedObjectContext _dealloc] + 4883 CoreData            0x1ac4919cc internalBlockToDeallocNSManagedObjectContext_block_invoke + 564 CoreData            0x1ac484410 developerSubmittedBlockToNSManagedObjectContextPerform + 1645 libdispatch.dylib       0x1a5fbcac8 _dispatch_client_callout6 libdispatch.dylib       0x1a5fc3c08 _dispatch_lane_serial_drain7 libdispatch.dylib       0x1a5fc4734 _dispatch_lane_invoke8 libdispatch.dylib       0x1a5fce528 _dispatch_workloop_worker_thread9 libsystem_pthread.dylib    0x1ed910908 _pthread_wqthread + 27610 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 + 7641 CoreFoundation         0x1a63ee414 CFBasicHashRemoveValue + 23842 CoreFoundation         0x1a6305ec0 CFDictionaryRemoveValue + 2363 CoreData            0x1ac3911c0 -[NSManagedObjectContext(_NSInternalAdditions) _forgetObject:propagateToObjectStore:removeFromRegistry:] + 1244 CoreData            0x1ac3706ec -[_PFManagedObjectReferenceQueue _processReferenceQueue:] + 8605 CoreData            0x1ac43c734 -[_PFAutoreleasePoolThunk dealloc] + 486 libobjc.A.dylib        0x1ba45781c AutoreleasePoolPage::releaseUntil(objc_object**) + 2047 libobjc.A.dylib        0x1ba4576e8 objc_autoreleasePoolPop + 2128 Foundation           0x1a75c8fa8 -[NSOperation start] + 13209 Foundation           0x1a76d9624 NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION + 2410 Foundation           0x1a76d90d0 NSOQSchedule_f + 18411 libdispatch.dylib       0x1a5fca834 _dispatch_block_async_invoke2 + 14812 libdispatch.dylib       0x1a5fbcac8 _dispatch_client_callout + 2013 libdispatch.dylib       0x1a5fbfd60 _dispatch_continuation_pop + 41614 libdispatch.dylib       0x1a5fbf494 _dispatch_async_redirect_invoke + 59215 libdispatch.dylib       0x1a5fcd104 _dispatch_root_queue_drain + 35616 libdispatch.dylib       0x1a5fcd8e8 _dispatch_worker_thread2 + 11617 libsystem_pthread.dylib    0x1ed9108cc _pthread_wqthread + 21618 libsystem_pthread.dylib    0x1ed91777c start_wqthread + 8


Crashed: NSManagedObjectContext 0x28034c340
EXCBADACCESS KERNINVALIDADDRESS 0x000000000000001c

Code Block Crashed: NSManagedObjectContext 0x28034c3400 libobjc.A.dylib        0x1ba43a53c object_getIndexedIvars + 361 CoreData            0x1ac4447a8 _PFObjectIDFastHash64 + 362 CoreFoundation         0x1a63ea4f8 CFBasicHashRehash + 9923 CoreFoundation         0x1a63ee414 CFBasicHashRemoveValue + 23844 CoreFoundation         0x1a6305ec0 CFDictionaryRemoveValue + 2365 CoreData            0x1ac3911c0 -[NSManagedObjectContext(_NSInternalAdditions) _forgetObject:propagateToObjectStore:removeFromRegistry:] + 1246 CoreData            0x1ac3706ec -[_PFManagedObjectReferenceQueue _processReferenceQueue:] + 8607 CoreData            0x1ac48e198 90-[NSManagedObjectContext(_NSInternalNotificationHandling) _registerAsyncReferenceCallback]_block_invoke + 728 CoreData            0x1ac484410 developerSubmittedBlockToNSManagedObjectContextPerform + 1649 libdispatch.dylib       0x1a5fbcac8 _dispatch_client_callout + 2010 libdispatch.dylib       0x1a5fc3c08 _dispatch_lane_serial_drain + 58011 libdispatch.dylib       0x1a5fc4734 _dispatch_lane_invoke + 40812 libdispatch.dylib       0x1a5fce528 _dispatch_workloop_worker_thread + 70813 libsystem_pthread.dylib    0x1ed910908 _pthread_wqthread + 27614 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 swiftlet 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?
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