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

Multithreading Violation while saving parent context #63

Closed
saurabytes opened this issue Mar 3, 2016 · 2 comments
Closed

Multithreading Violation while saving parent context #63

saurabytes opened this issue Mar 3, 2016 · 2 comments

Comments

@saurabytes
Copy link
Collaborator

Overview

I have enabled concurrency detection for multithread violations using
-com.apple.CoreData.ConcurrencyDebug 1 in the Run arguments
Since then every save I raising this flag. Currently it seems this is happening how the saves are being handled.
The violation happens in save context for parent after the NSManagedObjectContextDidSaveNotification is posted for the child context

screen shot 2016-03-03 at 10 45 38 am

#### Steps 1. Update `Run` in scheme for ExampleApp to have [`-com.apple.CoreData.ConcurrencyDebug 1`](http://oleb.net/media/xcode-scheme-core-data-concurrency-debug.png) 2. Add a company in the app 3. The app crashes with above stack trace `+[NSManagedObjectContext__Multithreading_Violation_AllThatIsLeftToUsIsHonor__] ()`
@saurabytes
Copy link
Collaborator Author

Fix

Looking more closely and verify with a test this is the resolution
The context hasChanges verification has to be thread safe too

    let block = {
        guard context.hasChanges else { return }
        do {
            try context.save()
            completion?(.Success)
        }
        catch {
            completion?(.Failure(error as NSError))
        }
    }

@jessesquires
Copy link
Owner

Thanks @saurabytes ! 👍

Closing as a duplicate of #59.

If you would like to submit a PR, please do! 😄

jessesquires added a commit that referenced this issue Mar 4, 2016
Fix #63: Move hasChanges to be performed in context
@jessesquires jessesquires added this to the 2.2.1 milestone Mar 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants