Not an issue, but I'd like the developer's opinion on this presentation #330

Closed
treddy73 opened this Issue Dec 3, 2012 · 13 comments

Comments

Projects
None yet
4 participants

treddy73 commented Dec 3, 2012

http://www.slideshare.net/Inferis/adventures-in-multithreaded-core-data

The author of the presentation seemed to suggest that Magical Record's handling of contexts is "dangerous" (slide 71). My app currently uses RHManagedObject and we're fighting subtle moc problems as our app grows more complicated. We're preparing to switch to Magical Record, but I don't want to go through this effort only to have the same kind of problems. The author of the presentation seems to suggest that we might.

Contributor

tonyarnold commented Dec 3, 2012

It's a bit hard to say where his "dangerous" thinking comes from — there are lots of mentions of subtle bugs, but nothing specific. I've used MagicalRecord in a large number of personal and professional projects over the last few years, and yes — there are situations where it can fall flat on it's face, that's much more true of Core Data than MR.

What are the MOC issues that you're seeing in your app? Perhaps we can advise before you make any big decisions.

treddy73 commented Dec 3, 2012

I believe this issue is specific to RHManagedObject... In a nutshell, say you fault in "Record A" on the main thread's MOC. Then in another thread's MOC, you fetch "Record A", change some data, then maybe in that same thread this "Record A" gets deleted because the parent table cascaded a delete. When the background thread attempts to mergeChangesFromContextDidSaveNotification, the "Record A" fault on the main MOC fires and fails because the record no longer exists. I believe it is specific to RHManagedObject because it fires a willAccessValueForKey:nil for every object in the MOC that is updated. That's probably confusing...I'm working on converting our unit test to demonstrate this crash to use Magical Record to see if it continues to crash.

Contributor

tonyarnold commented Dec 3, 2012

Yeah, that's kind of involved. If you're willing to share the unit test you write (even just in concept), we can look at adding it to our existing pool of tests. That way, if the problem exists in MR, we can look at fixing it — either way, please let me know!

treddy73 commented Dec 4, 2012

Here's some pseudocode...:

-(void)test {
    NSArray* array = [MyTable MR_findAll];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        MyTable* myTable = [MyTable MR_findFirst];
        ...change some properties on myTable...
        [[NSManagedObjectContext MR_contextForCurrentThread] MR_saveNestedContexts];  //might want to try the test without this line of code also...
        MyParentTable* myParentTable = ...get parent of myTable...
        [myParentTable MR_deleteEntity];
        [[NSManagedObjectContext MR_contextForCurrentThread] MR_saveNestedContexts];
    });
}
Contributor

tonyarnold commented Dec 4, 2012

So did this test pass when you'd converted it to use MR?

Also, is there a reason that you don't just make all of the changes to your MyTable entity, and to your MyParentTable entity, and then save?

treddy73 commented Dec 6, 2012

I'm going to close this issue becuase RHManagedObject follows the thread confinement pattern and it appears that MagicalRecord is using nested contexts. I think there was some issues specific to RHManagedObject that caused us some headaches.

@treddy73 treddy73 closed this Dec 6, 2012

chriscdn commented Dec 7, 2012

treddy73: I'm the author of RHManagedObject. If you have a test with RHManagedObject that causes it to crash I'd be grateful if you could share it with me. I once moved RHManagedObject to nested contexts, but that caused a whole bunch of other problems (specifically locking issues with iOS 5.1.1).

treddy73 commented Dec 7, 2012

@chriscdn - I may need to rollback to RHManagedObject because MagicalRecord is causing deadlocks for me. The more I read about nested contexts, the less I like... Here's another blog about why nested contexts aren't quite ready for production.

http://wbyoung.tumblr.com/post/27851725562/core-data-growing-pains

I would be happy to create an issue with test case but it seems that the "issues" tab doesn't show up half the time...

chriscdn commented Dec 7, 2012

@treddy73 - Funny, it was that article and the part on deadlocks that made me throw out nested contexts in RHManagedObject. Although it worked fine in iOS 6 I kept getting freezes with iOS 5.1.1.

Please keep me posted with any errors you find in RHManagedObject. My use of Core Data isn't very complicated (some table views and maps), so it's quite possible things may fail with more complex setups.

iOSDevil commented Dec 7, 2012

I'm scared after reading that, might have to drop back to an older version :)

On 7 Dec 2012, at 20:44, Christopher Meyer notifications@github.com wrote:

@treddy73 - Funny, it was that article and the part on deadlocks that made me throw out nested contexts in RHManagedObject. Although it worked fine in iOS 6 I kept getting freezes with iOS 5.1.1.

Please keep me posted with any errors you find in RHManagedObject. My use of Core Data isn't very complicated (some table views and maps), so it's quite possible things may fail with more complex setups.


Reply to this email directly or view it on GitHub.

Contributor

tonyarnold commented Dec 7, 2012

@treddy73, similar to @chriscdn's request, we'd be keen to find out more about the specific situations that are causing the deadlocks in your app while using MR. Anything you can provide would be helpful.

@iOSDevil, are you targeting iOS 5.x in your app?

iOSDevil commented Dec 7, 2012

I am targeting iOS 5.

But I've got some nagging doubts since switching to the latest version of MR.

I'll lurk for a bit and learn the best way to do big imports in the background :)

On 7 Dec 2012, at 21:53, Tony Arnold notifications@github.com wrote:

@treddy73, similar to @chriscdn's request, we'd be keen to find out more about the specific situations that are causing the deadlocks in your app while using MR. Anything you can provide would be helpful.

@iOSDevil, are you targeting iOS 5.x in your app?


Reply to this email directly or view it on GitHub.

treddy73 commented Dec 9, 2012

@tonyarnold trouble is it doesn't happen in a repeatable fashion. I'm afraid our application is quite database intensive and isolating a repeatable test case is difficult. I'll see what I can do. I do have to say that I'm using 2.0.7's MR_save which is performing a performBlockAndWait...so deadlocks are more likely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment