Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(iOS 12 beta 2) Multiple call of "MagicalRecord saveWithBlock:" freezes UI #1331

Open
ghost opened this issue Jun 25, 2018 · 11 comments
Open

Comments

@ghost
Copy link

ghost commented Jun 25, 2018

Hello,

In iOS 12 beta 2 I face the following issue.

I call from UI a method to update some data in my database with the following code:

[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
    Item *theItem = [FriendItem MR_findFirstWithPredicate:aPredicate inContext:localContext];
    [theItem setSomeData:data];
}];

The problem is when this function is called multiple times, the app freezes.

The console output is:

Created new private queue context: <NSManagedObjectContext: 0x281da8000>
Created new private queue context: <NSManagedObjectContext: 0x281d992c0>
→ Saving <NSManagedObjectContext (0x281da8000): saveWithBlock:completion:> on a background thread
→ Saving <NSManagedObjectContext (0x281d90960): MagicalRecord Root Saving Context> on a background thread

That was working for 2 years.
Is something that I missing, or there are changes in core data in iOS 12?

Τhanks in advance.

@laGrave
Copy link

laGrave commented Jul 9, 2018

Same issue on beta 3

@laGrave
Copy link

laGrave commented Jul 10, 2018

As I can see, code stuck at NSManagedObjectContext func "save:"

@fysteven
Copy link

Is this still an issue in the latest iOS 12 beta?

@s-gilroy
Copy link

s-gilroy commented Sep 12, 2018

Running the latest iOS beta I'm having the same issue.

@laGrave @fatourosfotis Did either of you ever figure out a workaround for this?

@s-gilroy
Copy link

To close the loop for anyone that is experiencing this issue. Seems like this is a bigger issue than Magical Record (https://forums.developer.apple.com/message/324460#324460).

Our temporary solution was to make the root context a main queue concurrency type and to have MR_defaultContext to return the root context instead. It's a bad fix but at least no more UI deadlocks.

@laGrave
Copy link

laGrave commented Sep 14, 2018

I've stuck with that issue and decided to quickly migrate to the Realm DB.
I'll try the method you suggested

@tuyenbq-0446
Copy link

i'm facing the same issue as you said but not sure why did happen anyway. Please tell me the reason if possible. thx

@AKyashkinCherryhome
Copy link

Is there still no solution yet? I'm facing the same issue with three simple "SaveWithBlockAndWait" calls.
It can handle two simultaneously calls, but it fails on three calls, which looks really odd to me.

@yaoqimin2013
Copy link

I'm facing the same issue, since changing the rootContext to a mainContext is not a good solution, I have to look for an alternate solution. Any advice >.<

@AKyashkinCherryhome
Copy link

This is what I basically did. I remade all my operations to work in synchronous mode in one background thread, which is fixed my issue, since all concurrent writings are gone. Not sure if that's a good one, probably will migrate to other DB as well.

// "global" var, stored in singleton Manager
dispatch_queue_t dispatchQueueSync = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

// sync write operation
dispatch_sync([[DataManager shared] dispatchQueueSync], ^{
    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
        // DB opertions
    }];
    
    dispatch_async(dispatch_get_main_queue(), ^{
        // refresh UI and stuff calls
    });
});

@shivam-ucreate
Copy link

shivam-ucreate commented Nov 1, 2018

Having the same issue in iOS 12 @AKyashkinCherryhome the above solution didn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants