Core Data Deadlocks

The current architecture of the apps is like:



NSPersistentStoreCoordinator

|

Root Context (Private Queue)

|

Main Thread Context (Main Thread Queue)

|

Background Operation Context(s) (Private Queue)


It has been working up until now without problem when in iOS 12, We ve got a deadlock:



Can anyone point us to the right direction here?

Replies

Having something similar. Distilling it down, looks like we've a:


// this is stored somewhere
let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)

DispatchQueue.main.async {
   //.. do work

   context.performAndWait {

   }
}


I think that the performAndWait isn't executed on a background thread, which you would expect due to the privateQueue. This is causing the freezing as we're doing lots of work on the main queue.


Do you have any other information on the issue?

We recently solved a similar issue by removing one of our contexts. We had our a main queue context writing into a private queue context which would then write to the persistent store coordinator (Same as your root context). This was done to offload saving to disk to a background queue. On iOS 12 beta 5, this seemed to be causing the deadlock. We pointed our main queue context to the store coordinator directly, and removed the final private queue context, which resolved it. Write now happen on the main thread, but the app runs.

We are encountering the same issue. Moved all save actions to the main thread, but this seems like a pretty lousy solution. Does anyone know if this is a known bug and if Apple is planning to address it?

I have the same problem. But moving everything to the main thread can not really be the solution for a usable app. Any updates on that?

+1 for Apple, please fix that.