soffes / ssdatakit

Eliminate your Core Data boilerplate code
MIT License
453 stars 57 forks source link

__privateQueueContext save causing deadlock #19

Closed hermanolsson closed 11 years ago

hermanolsson commented 11 years ago

I'm not totally sure of this, but I have big problems with deadlocks (together with NSFetchedResultsController) when saving the privateQueueContext via the NSManagedObjectContextDidSaveNotification block. The only way I have found to solve this problem is to force the performBlock: to be called on the main queue. The save is still executed on another queue but the deadlock seems to be gone.

Am I doing something terribly wrong here or might this solution be good enough for a pull request?

calebd commented 11 years ago

I'm not sure I know what you mean. Could you provide a code sample in a gist of the behavior you would like and the code you had to write to get around the bug?

Also, ideally you would never save anything directly to the main queue context as changes are not pulled from that into the main queue context without a manual fetch. This is designed to work just like UIManagedDocument. Saves should either be performed on the main queue context, or a private descendent of the main queue context.

hermanolsson commented 11 years ago

"Am I doing something terribly wrong [...] ?" Yes. I did.

I messed up the read/write + nested contexts a bit. That was really hard to debug since it only occurred sometimes.