drewmccormack / ensembles

A synchronization framework for Core Data.
MIT License
1.63k stars 131 forks source link

Calling Ensembles in applicationShouldTerminate: causes deadlock #170

Closed asciiz closed 10 years ago

asciiz commented 10 years ago

Ensembles v2, Dropbox, OS X 10.8.5, 10.9.4

If I am calling any of these methods (other not tested):

the completion block will never be called. I am seeing something like this: "Cancelling Merge <<< -[CDEPersistentStoreEnsemble cancelMergeWithCompletion:] line 766"

and that's it. This issue only occurs when the methods are called from applicationShouldTerminate:, otherwise it works.

My code is similar to the listing in the book (page 44).

drewmccormack commented 10 years ago

I think the problem is that the Dropbox API probably needs the run loop, and I think the run loop is no longer available at that point. Maybe you can do something in another method, or run the run loop explicitly yourself and exit from the callback.

Eg.

__block BOOL finished = NO; [ensemble mergeWithCompletion:^(NSError *error) { finished = YES; }]; while (!finished) [[NSRunLoop currentRunLoop] runUntilDate:...]

asciiz commented 10 years ago

Unfortunately, it still doesn't work (I am using the code as described in the book, page 57/58). iCloud works fine, Dropbox causes deadlock.

BTW, I noticed an error on page 58: I think "runBeforeDate" should be either "runUntilDate:" or "runMode:beforeDate:".

drewmccormack commented 10 years ago

Can you post the stack for the deadlock, or do a spindump with Activity Monitor?

asciiz commented 10 years ago

Sure, I'll send you the data via mail.

The last line logged is: Processing pending changes in ensemble <<< -[CDEPersistentStoreEnsemble processPendingChangesWithCompletion:] line 783

and the CPU usage will be 100% and the memory consumption raises up until there is no free memory anymore.

asciiz commented 10 years ago

Sorry, my fault.

I was using the wrong RunLoopMode. Now it works.

drewmccormack commented 10 years ago

Ah, great to hear! Thanks for letting me know. Kind regards, Drew

On 18 Aug 2014, at 16:49, asciiz notifications@github.com wrote:

Sorry, my fault.

I was using the wrong RunLoopMode. Now it works.

— Reply to this email directly or view it on GitHub.