Search code examples
iosobjective-cios6grand-central-dispatchnsmanagedobjectcontext

FetchRequest within Method called from performBlock NSPrivateQueueConcurrencyType failed


Within a performBlock I handoff its managedObjectContext to other methods which use it for core data access. The managedObjectContext is a NSPrivateQueueConcurrencyType and has the NSMainQueueconCurrencyType as a parent. As soon as one of the called methods within the performBlock execute a fetch request, the applications dies without any error. The OS X Console outputs the following:

BUG in libdispatch client: kevent[EVFILT_VNODE] add: "Bad file descriptor" - 0x9

Has anyone an idea what is causing this?

I'm using XCode 4.5.2 and iOS 6.

Update

I discovered that this problem only occurs within a SenTestingKit case as a static library. If I include the library into a regular iOS App it's gone. Any Ideas?


Solution

  • Wrapping your objects designed to be running on background threads into NSBlockOperation in a NSOperationQueue will alleviate queue blocking errors between your child and parent contexts.

    You should also remove the performBlock calls of your child context. Child automatically does requests to the parent queue on its private queue which automatically calls the parent context using the parent contexts performBlock. Your existing calls will work if your code happens to not be running on the main thread, but will cause a deadlock if it runs on the main thread (child and parent are locking main thread) which is what happens in a unit test. The only place I've seen this documented by Apple was in this 2012 WWDC video.

    https://developer.apple.com/videos/wwdc/2012/?id=214