0
votes

I have a problem with the CoreData and fulfilling managedObjects.

Stack trace:

Uncaught exception: CoreData could not fulfill a fault for '0x11cec410 <x-coredata://08BF0B39-BA5D-404E-B75E-FD4FA906DE3E/TaskDescription/p1747>'. Stack trace: (
"4   libc++abi.dylib                     0x03553f60 _ZSt11__terminatePFvvE + 14",
"5   libc++abi.dylib                     0x03553b97 __cxa_rethrow + 103",
"6   libobjc.A.dylib                     0x02cb0a57 objc_exception_rethrow + 47",
"7   CoreFoundation                      0x02f95bc5 CFRunLoopRunSpecific + 613",
"8   CoreFoundation                      0x02f9594b CFRunLoopRunInMode + 123"

)

 *** Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault for '0x11cec410 <x-coredata://08BF0B39-BA5D-404E-B75E-FD4FA906DE3E/TaskDescription/p1747>''
*** First throw call stack:
(
0   CoreFoundation                      0x02ff05e4 __exceptionPreprocess + 180
1   libobjc.A.dylib                     0x02cb08b6 objc_exception_throw + 44
2   CoreData                            0x0298666b _PFFaultHandlerLookupRow + 2715
3   CoreData                            0x02985bc7 -[NSFaultHandler fulfillFault:withContext:forIndex:] + 39
4   CoreData                            0x029857a3 _PF_FulfillDeferredFault + 259
5   CoreData                            0x029855f6 _sharedIMPL_pvfk_core + 70
6   CoreData                            0x0298a005 -[NSManagedObject(_PFDynamicAccessorsAndPropertySupport) _genericValueForKey:withIndex:flags:] + 85
7   CoreData                            0x029c3ab1 _PF_Handler_Public_GetProperty + 161
8   CoreData                            0x029c39b5 -[NSManagedObject valueForKey:] + 149
9   Foundation                          0x0254e065 -[NSFunctionExpression expressionValueWithObject:context:] + 1260
10  Foundation                          0x025d4109 -[NSComparisonPredicate evaluateWithObject:substitutionVariables:] + 248
11  Foundation                          0x025d4009 -[NSPredicate evaluateWithObject:] + 48
12  CoreData                            0x02a8f991 -[NSFetchedResultsController(PrivateMethods) _objectInResults:] + 113
13  CoreData                            0x02a912c2 -[NSFetchedResultsController(PrivateMethods) _preprocessUpdatedObjects:insertsInfo:deletesInfo:updatesInfo:sectionsWithDeletes:newSectionNames:treatAsRefreshes:] + 642
14  CoreData                            0x02a926f4 -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:] + 1892
15  Foundation                          0x02622e39 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke + 40
16  CoreFoundation                      0x0304c524 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
17  CoreFoundation                      0x02fa407b _CFXNotificationPost + 2859
18  Foundation                          0x0255cb91 -[NSNotificationCenter postNotificationName:object:userInfo:] + 98
19  CoreData                            0x029974a3 -[NSManagedObjectContext(_NSInternalNotificationHandling) _postObjectsDidChangeNotificationWithUserInfo:] + 83
20  CoreData                            0x02a36abf -[NSManagedObjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:withDeletions:withUpdates:withRefreshes:] + 367
21  CoreData                            0x02993168 -[NSManagedObjectContext(_NSInternalChangeProcessing) _postRefreshedObjectsNotificationAndClearList] + 136
22  CoreData                            0x02992d14 -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:] + 3140
23  CoreData                            0x029920c9 -[NSManagedObjectContext processPendingChanges] + 41
24  CoreData                            0x02966311 _performRunLoopAction + 321
25  CoreFoundation                      0x02fb853e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
26  CoreFoundation                      0x02fb848f __CFRunLoopDoObservers + 399
27  CoreFoundation                      0x02f963b4 __CFRunLoopRun + 1076
28  CoreFoundation                      0x02f95b33 CFRunLoopRunSpecific + 467
29  CoreFoundation                      0x02f9594b CFRunLoopRunInMode + 123
30  GraphicsServices                    0x0488d9d7 GSEventRunModal + 192
31  GraphicsServices                    0x0488d7fe GSEventRun + 104
32  UIKit                               0x016c294b UIApplicationMain + 1225
33  MYAPP                              0x0003bb9d main + 141
34  MYAPP                              0x00003055 start + 53
)
libc++abi.dylib: terminating with uncaught exception of type _NSCoreDataException

All I can see when app crashes is that trace with only showing some internal CoreData/Foundation instructions. Can anyone please explain me, what is going on with that

NSFetchedResultsController(PrivateMethods)

or

NSManagedObjectContext(_NSInternalChangeProcessing)

It looks very weird to me. How can I prevent from such NSObjectInaccessibleException? I know that this error is due to previously deleted object. I have many background contexts run asynchronously, but I think that I am keeping the rules given by Apple documentation about concurrency with CoreData. It crashes only sometimes and I can't see anything from this point. Anyone had similar situation?

1
You are trying to do something with an object that has been deleted. Check if the object is deleted before you try using it.Duncan Groenewald
I agree, but the issue occurs when merging coredata moc on main thread. Even when trying to check and ignore objects that no longer exists (method listening for ContextDidSaveNotification) the issue occurs somewhere higher. Like two mocs are in the consistent state, but both want to delete object. When first do a deletion, then next is erroring (when merging changes of course).piotr_ch

1 Answers

2
votes

This has nothing to do with the methods you mentioned.
Nor can you avoid this issue in a multi-context environment where you have more then one child context with the same parent (nil parent included).

This might happen in a multi-context environment (or some unique cases) where one context hold a fault for some object (which he consider to exist) but in the mean time another context delete the object from the store and not notifying the other context of the deletion (before the context holding the fault attempt to fulfil it.

Using a FRC in a multi-context environment ,which does not use a parent child architecture where the FRC context is the parent for all child contexts will always be vulnerable to this exception.

See HERE for some more usecases.

A possible solution would be to delay your actual deletion of FRC tracked objects:
first mark them for deletion (your FRC predicate should take this new property into account)
Then use a background operation to delete objects that were marked for deletion (every given time interval)

A partial solution would be to use a parent child context architecture funnelling all events through the context the FRC is observing.
This is a partial solution due to the fact that this move the problem one level up to the child contexts that are unaware of each other deletions (if child contexts never deal with the same objects in parallel then you might avoid this issue).