Coder Social home page Coder Social logo

grahamdennis / gdcoredataconcurrencydebugging Goto Github PK

View Code? Open in Web Editor NEW
171.0 171.0 23.0 127 KB

GDCoreDataConcurrencyDebugging helps you find cases where NSManagedObject's are being called on the wrong thread or dispatch queue.

License: MIT License

Objective-C 91.02% Ruby 8.98%

gdcoredataconcurrencydebugging's People

Contributors

grahamdennis avatar padraigk avatar petrocket avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gdcoredataconcurrencydebugging's Issues

Can't install v. 0.2

My pod file:
pod 'GDCoreDataConcurrencyDebugging', '~> 0.2'

After pod install:

[!] Unable to satisfy the following requirements:

  • GDCoreDataConcurrencyDebugging (~> 0.2) required by Podfile

PrivateConcurrency type MOC on a background thread nested with a MainConcurrency type MOC raises issues

After my first (failed) attempt to report an issue with GDCoreDataConcurrencyDebugging I have been debugging further my app and I am faced with problem that I don't understand,I believe I am doing things correctly, only using objects local to the MOC, within the boundary of a performBlock(AndWait) yet I get issues reported by GDCoreDataConcurrencyDebugging and I can't get my head around it, all seems to happen when a NSManagedObject is passed from the MOC to its parent

I have put a sample project up on github to illustrate https://github.com/pierrephi/CoreDataNightMare

If I execute everything on the main (i.e. I remove the dispatch_async on the background queue, I get no error)

Hope all that makes sense and the example allows you to pinpoint the issue

[Question] Invalid concurrent access to managed object calling 'release'

With this code: (Also uses MagicalRecord: https://github.com/magicalpanda/MagicalRecord)

    @autoreleasepool {
        NSManagedObjectContext * importContext = [NSManagedObjectContext MR_context];
        importContext.undoManager = nil;
        [importContext performBlockAndWait: ^{
            NSUInteger countryCount = [Country MR_findAllInContext: importContext].count;
            NSLog(@"We have %ld countries.",
                  countryCount
                  );
        }];
    }

I get the following:

Invalid concurrent access to managed object calling 'release'; Stacktrace: (
    0   AppWage                             0x000000010065fe67 ValidateConcurrency + 183
    1   AppWage                             0x000000010065fb18 CustomSubclassRelease + 40
    2   CoreData                            0x00007fff968e05d3 -[_PFArray dealloc] + 99
    3   libobjc.A.dylib                     0x00007fff9351665a _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 502
    4   AppWage                             0x000000010007768a -[AppDelegate initData] + 506
    5   AppWage                             0x000000010007485a __28-[AppDelegate initializeApp]_block_invoke + 42
    6   libdispatch.dylib                   0x00007fff939451d7 _dispatch_call_block_and_release + 12
    7   libdispatch.dylib                   0x00007fff939422ad _dispatch_client_callout + 8
    8   libdispatch.dylib                   0x00007fff9394409e _dispatch_root_queue_drain + 326
    9   libdispatch.dylib                   0x00007fff93945193 _dispatch_worker_thread2 + 40
    10  libsystem_pthread.dylib             0x00007fff90058ef8 _pthread_wqthread + 314
    11  libsystem_pthread.dylib             0x00007fff9005bfb9 start_wqthread + 13
)

But everything here is nicely self contained. Nothing from the importContext is accessed anywhere outside of the block and/or the autorelease pool. Is this a bug with GDCoreDataConcurrencyDebugging, or am I doing something wrong here?

EXC_BAD_ACCESS when wrapping code into dispatch_async

dispatch_async(backgroundQueue , ^
    {
        NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
        dispatch_async(dispatch_get_main_queue(), ^
        {
            NSManagedObjectContext *context = [NSManagedObjectContext MR_context];
            [context performBlockAndWait:^
            {
                 NSManagedObject *object = [context objectWithID:identityCardId];
                 [object setValue:imageData forKey:imageDataProperty];
                 [context KK_SaveToPersistentStore];

            }];

            UIImage *image = [UIImage imageWithData:imageData];
            callback(image);
        });
    });

Here is few screenshots with app state that could help you with debugging
screen shot 2014-01-15 at 13 56 12
screen shot 2014-01-15 at 13 55 54

This is my code that is calling this exception.
screen shot 2014-01-15 at 13 55 47

Invalid concurrent access to managed object calling 'release'; Stacktrace

Hi i'm getting following warnings in my code.

2016-05-31 17:13:16.988 ABC-iPhone[5183:2764409] Invalid concurrent access to managed object calling 'release'; Stacktrace: (
    0   ABC-iPhone                   0x0000000100874ad0 ValidateConcurrency + 248
    1   ABC-iPhone                   0x0000000100874698 CustomSubclassRelease + 32
    2   ABC-iPhone                   0x00000001004c6710 _TFC17ABC_iPhone10SWCProductcfT6entityCSo19NSEntityDescription30insertIntoManagedObjectContextGSqCSo22NSManagedObjectContext__S0_ + 136
    3   ABC-iPhone                   0x00000001003734c0 _TFC17ABC_iPhone16SWCPickedProductcfT6entityCSo19NSEntityDescription30insertIntoManagedObjectContextGSqCSo22NSManagedObjectContext__S0_ + 80
    4   ABC-iPhone                   0x0000000100373548 _TToFC17ABC_iPhone16SWCPickedProductcfT6entityCSo19NSEntityDescription30insertIntoManagedObjectContextGSqCSo22NSManagedObjectContext__S0_ + 76
    5   CoreData                            0x00000001845505cc <redacted> + 172
    6   CoreData                            0x000000018454f0dc <redacted> + 180
    7   CoreData                            0x00000001845e2490 <redacted> + 784
    8   CoreData                            0x00000001845e2a50 <redacted> + 348
    9   CoreData                            0x00000001845e4d8c <redacted> + 108
    10  libdispatch.dylib                   0x0000000101e41a3c _dispatch_client_callout + 16
    11  libdispatch.dylib                   0x0000000101e52040 _dispatch_barrier_sync_f_slow_invoke + 736
    12  libdispatch.dylib                   0x0000000101e41a3c _dispatch_client_callout + 16
    13  libdispatch.dylib                   0x0000000101e474e4 _dispatch_main_queue_callback_4CF + 2096
    14  CoreFoundation                      0x0000000182690d50 <redacted> + 12
    15  CoreFoundation                      0x000000018268ebb8 <redacted> + 1628
    16  CoreFoundation                      0x00000001825b8c50 CFRunLoopRunSpecific + 384
    17  GraphicsServices                    0x0000000183ea0088 GSEventRunModal + 180
    18  UIKit                               0x00000001878a2088 UIApplicationMain + 204
    19  ABC-iPhone                   0x0000000100737a88 main + 144
    20  libdyld.dylib                       0x00000001821568b8 <redacted> + 4
)
2016-05-31 17:13:16.991 SweetCouch-iPhone[5183:2764409] Invalid concurrent access to managed object calling 'release'; Stacktrace: (
    0   ABC-iPhone                   0x0000000100874ad0 ValidateConcurrency + 248
    1   ABC-iPhone                   0x0000000100874698 CustomSubclassRelease + 32
    2   ABC-iPhone                   0x00000001003734ec _TFC17ABC_iPhone16SWCPickedProductcfT6entityCSo19NSEntityDescription30insertIntoManagedObjectContextGSqCSo22NSManagedObjectContext__S0_ + 124
    3   ABC-iPhone                   0x0000000100373548 _TToFC17ABC_iPhone16SWCPickedProductcfT6entityCSo19NSEntityDescription30insertIntoManagedObjectContextGSqCSo22NSManagedObjectContext__S0_ + 76
    4   CoreData                            0x00000001845505cc <redacted> + 172
    5   CoreData                            0x000000018454f0dc <redacted> + 180
    6   CoreData                            0x00000001845e2490 <redacted> + 784
    7   CoreData                            0x00000001845e2a50 <redacted> + 348
    8   CoreData                            0x00000001845e4d8c <redacted> + 108
    9   libdispatch.dylib                   0x0000000101e41a3c _dispatch_client_callout + 16
    10  libdispatch.dylib                   0x0000000101e52040 _dispatch_barrier_sync_f_slow_invoke + 736
    11  libdispatch.dylib                   0x0000000101e41a3c _dispatch_client_callout + 16
    12  libdispatch.dylib                   0x0000000101e474e4 _dispatch_main_queue_callback_4CF + 2096
    13  CoreFoundation                      0x0000000182690d50 <redacted> + 12
    14  CoreFoundation                      0x000000018268ebb8 <redacted> + 1628
    15  CoreFoundation                      0x00000001825b8c50 CFRunLoopRunSpecific + 384
    16  GraphicsServices                    0x0000000183ea0088 GSEventRunModal + 180
    17  UIKit                               0x00000001878a2088 UIApplicationMain + 204
    18  ABC-iPhone                   0x0000000100737a88 main + 144
    19  libdyld.dylib                       0x00000001821568b8 <redacted> + 4
)
2016-05-31 17:13:16.995 SweetCouch-iPhone[5183:2764409] Invalid concurrent access to managed object calling 'release'; Stacktrace: (
    0   ABC-iPhone                   0x0000000100874ad0 ValidateConcurrency + 248
    1   ABC-iPhone                   0x0000000100874698 CustomSubclassRelease + 32
    2   ABC-iPhone                   0x00000001004c6710 _TFC17ABC_iPhone10SWCProductcfT6entityCSo19NSEntityDescription30insertIntoManagedObjectContextGSqCSo22NSManagedObjectContext__S0_ + 136
    3   ABC-iPhone                   0x00000001003734c0 _TFC17ABC_iPhone16SWCPickedProductcfT6entityCSo19NSEntityDescription30insertIntoManagedObjectContextGSqCSo22NSManagedObjectContext__S0_ + 80
    4   ABC-iPhone                   0x0000000100373548 _TToFC17ABC_iPhone16SWCPickedProductcfT6entityCSo19NSEntityDescription30insertIntoManagedObjectContextGSqCSo22NSManagedObjectContext__S0_ + 76
    5   CoreData                            0x00000001845505cc <redacted> + 172
    6   CoreData                            0x000000018454f0dc <redacted> + 180
    7   CoreData                            0x00000001845e2490 <redacted> + 784
    8   CoreData                            0x00000001845e2a50 <redacted> + 348
    9   CoreData                            0x00000001845e4d8c <redacted> + 108
    10  libdispatch.dylib                   0x0000000101e41a3c _dispatch_client_callout + 16
    11  libdispatch.dylib                   0x0000000101e52040 _dispatch_barrier_sync_f_slow_invoke + 736
    12  libdispatch.dylib                   0x0000000101e41a3c _dispatch_client_callout + 16
    13  libdispatch.dylib                   0x0000000101e474e4 _dispatch_main_queue_callback_4CF + 2096
    14  CoreFoundation                      0x0000000182690d50 <redacted> + 12
    15  CoreFoundation                      0x000000018268ebb8 <redacted> + 1628
    16  CoreFoundation                      0x00000001825b8c50 CFRunLoopRunSpecific + 384
    17  GraphicsServices                    0x0000000183ea0088 GSEventRunModal + 180
    18  UIKit                               0x00000001878a2088 UIApplicationMain + 204
    19  ABC-iPhone                   0x0000000100737a88 main + 144
    20  libdyld.dylib                       0x00000001821568b8 <redacted> + 4
)
2016-05-31 17:13:16.998 SweetCouch-iPhone[5183:2764409] Invalid concurrent access to managed object calling 'release'; Stacktrace: (
    0   ABC-iPhone                   0x0000000100874ad0 ValidateConcurrency + 248
    1   ABC-iPhone                   0x0000000100874698 CustomSubclassRelease + 32
    2   ABC-iPhone                   0x00000001003734ec _TFC17ABC_iPhone16SWCPickedProductcfT6entityCSo19NSEntityDescription30insertIntoManagedObjectContextGSqCSo22NSManagedObjectContext__S0_ + 124
    3   ABC-iPhone                   0x0000000100373548 _TToFC17ABC_iPhone16SWCPickedProductcfT6entityCSo19NSEntityDescription30insertIntoManagedObjectContextGSqCSo22NSManagedObjectContext__S0_ + 76
    4   CoreData                            0x00000001845505cc <redacted> + 172
    5   CoreData                            0x000000018454f0dc <redacted> + 180
    6   CoreData                            0x00000001845e2490 <redacted> + 784
    7   CoreData                            0x00000001845e2a50 <redacted> + 348
    8   CoreData                            0x00000001845e4d8c <redacted> + 108
    9   libdispatch.dylib                   0x0000000101e41a3c _dispatch_client_callout + 16
    10  libdispatch.dylib                   0x0000000101e52040 _dispatch_barrier_sync_f_slow_invoke + 736
    11  libdispatch.dylib                   0x0000000101e41a3c _dispatch_client_callout + 16
    12  libdispatch.dylib                   0x0000000101e474e4 _dispatch_main_queue_callback_4CF + 2096
    13  CoreFoundation                      0x0000000182690d50 <redacted> + 12
    14  CoreFoundation                      0x000000018268ebb8 <redacted> + 1628
    15  CoreFoundation                      0x00000001825b8c50 CFRunLoopRunSpecific + 384
    16  GraphicsServices                    0x0000000183ea0088 GSEventRunModal + 180
    17  UIKit                               0x00000001878a2088 UIApplicationMain + 204
    18  ABC-iPhone                   0x0000000100737a88 main + 144
    19  libdyld.dylib                       0x00000001821568b8 <redacted> + 4
)
.
.
.
So on

I'm using 4 different Managed Object Models and their 4 respective Persistent Store Coordinators.
There are 2 Managed Object Context for each coordinator, one context is for main thread, and other is for background lengthy operations.
I'm pretty sure i'm not accessing contexts on multiple threads, doing all operations within perform block of respective context.
I'm using swift 2.0
I'm not sure whats happening here, plz help.
Following is the code where i'm accessing data, and getting this warning

//Using this context for main thread    
internal lazy var managedObjectContext: NSManagedObjectContext? = {
        let coordinator = self.persistentStoreCoordinator
        if coordinator == nil {
            return nil
        }
        var managedObjectContext = NSManagedObjectContext(concurrencyType: NSManagedObjectContextConcurrencyType.MainQueueConcurrencyType)
        managedObjectContext.persistentStoreCoordinator = coordinator
        return managedObjectContext
        }()
//Using this context for background operations
    internal lazy var managedObjectContext_lenghtyThread: NSManagedObjectContext? = {
        if self.managedObjectContext == nil{return nil}
        var managedObjectContext_lenghtyThread = NSManagedObjectContext(concurrencyType: NSManagedObjectContextConcurrencyType.PrivateQueueConcurrencyType)
        managedObjectContext_lenghtyThread.parentContext = self.managedObjectContext
        return managedObjectContext_lenghtyThread
        }()

//Here i'm getting this warning
        let fetchRequest = NSFetchRequest(entityName: self.ENTITY_SWCPickedProduct)
        self.managedObjectContext_lenghtyThread?.performBlock({ () -> Void in
            let resultOject:AnyObject? = try?     
            self.managedObjectContext_lenghtyThread!.executeFetchRequest(fetchRequest)
            if resultOject is [SWCPickedProduct]
            {
            }
        })

[Question / Issue?] NSOperation Serial Queue + GDCoreDataConcurrencyDebugging = false positive?

First of all: Thanks for the project!

It helped me finding at least one issue im my code yet and I guess there are more since I haven't tested all aspects of that app.

But right now I'm struggling with something which I think (since a few minutes) isn't an issue of my code but more an issue with the implementation of ValidateConcurrency.

I'm using NSURLSession in my app. For the background downloading stuff it needs a serial NSOperationQueue where it will make all callbacks. I have a dedicated NSManagedObjectContext (NSConfinementConcurrencyType) for that Queue.

Right now I get lots of warnings from GDCoreDataConcurrencyDebugging that I tried to understand or solve but couldn't find any issues in my code. But I guess I know the reason now: The NSOperationQueue in serial mode does always use only one thread but not always the same thread. So my context is created when needed (in the getter) and concurrencyIdentifier is set to that thread/dispatch_queue which the NSOperationQueue is using at that time. Sometime during the runtime of the app (my guess is when the NSOperationQueue is empty for a certain period of time) the dispatch_queue changes and so ValidateConcurrency returns NO.

Does that make sense, would you agree with my findings or do you see any other issues?

So basically instead of only looking at the current dispatch queue for a context with NSConfinementConcurrencyType we could also check if the context is inside a NSOperationQueue ([NSOperationQueue currentQueue]) and if this is a serial queue (maxConcurrentOperationCount == 1) and then use the NSOperationQueue as the concurrencyIdentifier. What do you think?

(false) positives with MagicalRecord?

I'm using it together with MagicalRecord and do get lots and lots of the following log messages:

2015-11-06 07:41:49.959 ...[31123:10196439] Invalid concurrent access to managed object calling 'release'; Stacktrace: (
    0   ...                            0x000000010f324c64 ValidateConcurrency + 212
    1   ...                            0x000000010f3248ed CustomSubclassRelease + 29
    2   CoreFoundation                      0x0000000113156b6d -[__NSArrayM dealloc] + 157
    3   libobjc.A.dylib                     0x000000011419bafe _ZN11objc_object17sidetable_releaseEb + 232
    4   CoreData                            0x000000010fd2c718 -[NSInPredicateOperator(_NSCoreDataSQLPredicateCategories) minimalFormInContext:ofPredicate:] + 1000
    5   CoreData                            0x000000010fe36df6 -[NSSQLGenerator initializeContextForRequest:ignoreInheritance:nestingLevel:] + 486
    6   CoreData                            0x000000010fe36f94 -[NSSQLGenerator initializeContextForFetchRequest:ignoreInheritance:nestingLevel:nestIsWhereScoped:] + 36
    7   CoreData                            0x000000010fe37262 -[NSSQLGenerator newSQLStatementForRequest:ignoreInheritance:countOnly:nestingLevel:nestIsWhereScoped:] + 98

The code which produces this e.g. is the following:

        MagicalRecord.saveWithBlockAndWait({ (localContext) -> Void in
            MyCoreDataClass.MR_truncateAllInContext(localContext)
        })

This should be perfectly fine, right?

I include GDCoreDataConcurrencyDebugging with CococaPods:

pod "GDCoreDataConcurrencyDebugging", :git => '[email protected]:GrahamDennis/GDCoreDataConcurrencyDebugging.git', :tag => '0.2', :configurations => ['Debug'], :submodules => true

Mismatched class names - more swizzling required?

Hi,

I've noticed that after linking to your project getting the class name using NSStringFromClass(self) does not match the value from calling NSEntityDescription -managedObjectClassName.

As a contrived example:

MyClass *mc = (...);
NSString *myClassName = NSStringFromClass(mc); // equals 'MyClass'

NSArray *entityDescriptions = [[[managedObjectContext persistentStoreCoordinator] managedObjectModel] entities];

NSEntityDescription *thisDescription = nil;
for( NSEntityDescription *eachEntity in entityDescriptions ) {
    /* [eachEntity managedObjectClassName] evaluates to 'MyClass_GDCoreDataConcurrencyDebugging' */
    if( [[eachEntity managedObjectClassName] isEqualToString: myClassName e] ) {
        thisDescription = eachEntity;
        break;
    }
}

I wouldn't file this as a bug but perhaps you can add more swizzling so that existing code that uses NSStringFromClass can function as expected after linking to your project.

Thanks for the great project!

Checking release-safety is unnecessary?

Hi there - in "Core Data Best Practices" (2012 WWDC), they say "Retain, release are always thread safe on Core Data objects".

Given that, is the CustomSubclassRelease check necessary? I get a lot of warnings from autoreleased objects created in performBlockAndWait, which later get released outside of the block.

Incompatibility with object hierarchy

I have been using this utility for a while now and recently I upgraded my data model to something a bit more complex with object inheritance

Lets say I have 2 base classes

IMIRegister and IMIRegisterItem both are abstract
and IMIRegister references a collection of IMIRegisterItems (to many relationship "items")
IMIRegisterItem has a reverse relationship "registre" and at some point I assign

IMIRegister *aRegister;
IMIRegisterItem *aRegisterItem;

aRegisterItem.register = aRegister

in my code both aRegisterItem and aRegister are of the base class type but at runtime they are of a concrete type, it seems that class name fiddling performed by GDCoreDataConcurrencyDebugging prevents the objective C CoreData run-time to correctly recognise the concrete type instance as a valid pointer to the abstract type

2014-03-17 22:10:46.614 Kotoba![688:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for to-one relationship: property = "registre"; desired type = IMIRegister_GDCoreDataConcurrencyDebugging; given type = IMIHistoryRegister_GDCoreDataConcurrencyDebugging; value = <IMIHistoryRegister_GDCoreDataConcurrencyDebugging: 0x17dea6a0> (entity: IMIHistoryRegister; id: 0x17dd5e50 <x-coredata://D5693539-058C-4896-A231-E5B74A8A83C9/IMIHistoryRegister/p50> ; data: {
    atime = "2014-03-17 21:10:16 +0000";
    ctime = "2013-08-19 14:56:07 +0000";
    items =     (
        "0x17f75770 <x-coredata://D5693539-058C-4896-A231-E5B74A8A83C9/IMIDictionarySearchItem/p4983>",
        "0x17f6e090 <x-coredata://D5693539-058C-4896-A231-E5B74A8A83C9/IMIDictionarySearchItem/p5007>",
        "0x17f77e90 <x-coredata://D5693539-058C-4896-A231-E5B74A8A83C9/IMIConjugationItem/p5112>",
        "0x17f6dfe0 <x-coredata://D5693539-058C-4896-A231-E5B74A8A83C9/IMIDictionarySearchItem/p4990>",
        "0x17f757a0 <x-coredata://D5693539-058C-4896-A231-E5B74A8A83C9/IMIDictionarySearchItem/p4986>",
        "0x17f6dff0 <x-coredata://D5693539-058C-4896-A231-E5B74A8A83C9/IMIDictionarySearchItem/p4991>",
        "0x17f6e0e0 <x-coredata://D5693539-058C-4896-A231-E5B74A8A83C9/IMIKanjiItem/p5015>",
        "0x17f6dfd0 <x-coredata://D5693539-058C-4896-A231-E5B74A8A83C9/IMIDictionaryItem/p4988>",
        "0x17f5ebc0 <x-coredata://D5693539-058C-4896-A231-E5B74A8A83C9/IMIDictionarySearchItem/p4974>",
        "0x17f6e050 <x-coredata://D5693539-058C-4896-A231-E5B74A8A83C9/IMIDictionaryItem/p4997>",
        "(...and 39 more...)"
    );
    name = History;
    parentRegister = nil;
    position = 0;
    subRegisters = "<relationship fault: 0x17e07690 'subRegisters'>";
    type = 0;
}).'
*** First throw call stack:
(0x2e5baf03 0x38d4fce7 0x2e32eb3d 0x2e32d515 0x17d5f5 0x17d0a1 0x182def 0x186083 0x2e3929cd 0x2e392b13 0x185f97 0xe35bb 0x14ecdf 0x30f087f3 0x30fbacb3 0x30e69e09 0x30de2b57 0x2e586031 0x2e5839bf 0x2e583d0b 0x2e4ee7a9 0x2e4ee58b 0x3345b6d3 0x30e4d891 0xbc9c7 0x3924dab7)

If this is not clear I will try and make a small example to reproduce

Error when use NSPrivateQueueConcurrencyType in main thread.

There is an empty project with just one function in the appDelegate for test -

- (void)test
{
    NSManagedObjectContext *context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
    Event *a = [Event insertInManagedObjectContext:context];
}

Error messages in the console

2013-10-11 16:40:42.567 Festival[87700:c07] Invalid concurrent access to managed object calling 'autorelease'; Stacktrace: (
0 Festival 0x00005767 ValidateConcurrency + 183
1 Festival 0x00005400 CustomSubclassAutorelease + 48
2 CoreData 0x000aa0af +[NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext:] + 143
3 Festival 0x000036b2 +[_Event insertInManagedObjectContext:] + 322
4 Festival 0x000031d3 -[RFAppDelegate test] + 195
5 Festival 0x000032d7 -[RFAppDelegate application:didFinishLaunchingWithOptions:] + 151
6 UIKit 0x00969157 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 266
7 UIKit 0x00969747 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1248
8 UIKit 0x0096a94b -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 805
9 UIKit 0x0097bcb5 -[UIApplication handleEvent:withNewEvent:] + 1022
10 UIKit 0x0097cbeb -[UIApplication sendEvent:] + 85
11 UIKit 0x0096e698 _UIApplicationHandleEvent + 9874
12 GraphicsServices 0x0270adf9 _PurpleEventCallback + 339
13 GraphicsServices 0x0270aad0 PurpleEventCallback + 46
14 CoreFoundation 0x0156fbf5 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 53
15 CoreFoundation 0x0156f962 CFRunLoopDoSource1 + 146
16 CoreFoundation 0x015a0bb6 __CFRunLoopRun + 2118
17 CoreFoundation 0x0159ff44 CFRunLoopRunSpecific + 276
18 CoreFoundation 0x0159fe1b CFRunLoopRunInMode + 123
19 UIKit 0x0096a17a -[UIApplication _run] + 774
20 UIKit 0x0096bffc UIApplicationMain + 1211
21 Festival 0x00002a9d main + 141
22 libdyld.dylib 0x02442725 start + 0
)
2013-10-11 16:40:42.569 Festival[87700:c07] Invalid concurrent access to managed object calling 'autorelease'; Stacktrace: (
0 Festival 0x00005767 ValidateConcurrency + 183
1 Festival 0x00005400 CustomSubclassAutorelease + 48
2 libobjc.A.dylib 0x01431d53 objc_autorelease + 51
3 Festival 0x000036eb +[_Event insertInManagedObjectContext:] + 379
4 Festival 0x000031d3 -[RFAppDelegate test] + 195
5 Festival 0x000032d7 -[RFAppDelegate application:didFinishLaunchingWithOptions:] + 151
6 UIKit 0x00969157 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 266
7 UIKit 0x00969747 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1248
8 UIKit 0x0096a94b -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 805
9 UIKit 0x0097bcb5 -[UIApplication handleEvent:withNewEvent:] + 1022
10 UIKit 0x0097cbeb -[UIApplication sendEvent:] + 85
11 UIKit 0x0096e698 _UIApplicationHandleEvent + 9874
12 GraphicsServices 0x0270adf9 _PurpleEventCallback + 339
13 GraphicsServices 0x0270aad0 PurpleEventCallback + 46
14 CoreFoundation 0x0156fbf5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION
+ 53
15 CoreFoundation 0x0156f962 __CFRunLoopDoSource1 + 146
16 CoreFoundation 0x015a0bb6 __CFRunLoopRun + 2118
17 CoreFoundation 0x0159ff44 CFRunLoopRunSpecific + 276
18 CoreFoundation 0x0159fe1b CFRunLoopRunInMode + 123
19 UIKit 0x0096a17a -[UIApplication _run] + 774
20 UIKit 0x0096bffc UIApplicationMain + 1211
21 Festival 0x00002a9d main + 141
22 libdyld.dylib 0x02442725 start + 0

I got invalid concurrent access delete

Hi

I just tried this library. It looks promising. But when I tried it I got this

Invalid concurrent access to managed object calling 'release'; Stacktrace: (
0 atlascopcoconstruction-ios 0x00353e5b ValidateConcurrency + 267
1 atlascopcoconstruction-ios 0x00353a54 CustomSubclassRelease + 36
2 libobjc.A.dylib 0x03f1deb1 objc_release + 65
3 libobjc.A.dylib 0x03f1de68 objc_storeStrong + 39
4 atlascopcoconstruction-ios 0x001118d4 -[ACCCDataManager(Parsing) getRootProductFileWithContext:] + 452
5 atlascopcoconstruction-ios 0x00198d75 -[ACCCDataManager getAllSizeTextWithContext:] + 85
6 atlascopcoconstruction-ios 0x00168357 __42-[SettingsViewController reloadFolderSize]_block_invoke + 327
7 libdispatch.dylib 0x04792c2a _dispatch_call_block_and_release + 15
8 libdispatch.dylib 0x047b008f _dispatch_client_callout + 14
9 libdispatch.dylib 0x0479a342 _dispatch_root_queue_drain + 671
10 libdispatch.dylib 0x0479b592 _dispatch_worker_thread2 + 45
11 libsystem_pthread.dylib 0x04b02dab _pthread_wqthread + 336
12 libsystem_pthread.dylib 0x04b06cce start_wqthread + 30
)

I use autoreleasepool, and I got this at the end of autoreleasepool block. It's in the same thread.

@autoreleasepool{
    NSPredicate *filterPredicate = [NSPredicate predicateWithFormat:@"name = %@", @"PRODUCT"];
    NSFetchRequest *fileRequest = [CDFile MR_requestAllWithPredicate:filterPredicate inContext:context];
    NSArray *files = [CDFile MR_executeFetchRequest:fileRequest inContext:context];
    if(files.count == 0){
    }else{
        if(files.count > 1){
            LogWarning(@"There are %d CDFile with 'PRODUCT' name", files.count);
        }
        cdFile = [files objectAtIndex:0];
    }
}   <----------- THIS LINE

My code and this library code are called in same thread.

This is my stack trace.
screen shot 2014-08-14 at 1 11 07 pm

Disable debugging in Production version

Hi,

This library is very useful to debug the core data concurrency.
But my concern is, how to disable this debugging in production(Adhoc or Distribution) version. Should i want to remove the library when the app go to production?

Is there any option to disable this library when the app run in production mode?

Confused about an error

I'm getting an error using the following code:

let context: NSManagedObjectContext = self.getPrivateContext()

context.performBlockAndWait {
        if let key = self.appDelegate.APIKey {
            apiKey = key
        } else {
            if let key: String = self.appDelegate.MainCoreDataService.getApiKeyFromDatabase(context) where key != "" {
                apiKey = key
                self.appDelegate.APIKey = key
            }
        }
}


internal func getApiKeyFromDatabase(context: NSManagedObjectContext) -> String? {
    let fetchRequest: NSFetchRequest = NSFetchRequest()
    if let entity: NSEntityDescription = NSEntityDescription.entityForName(Constants.CoreData.Device.NameOfTable, inManagedObjectContext: context) {
        // Edit the entity name as appropriate.
        fetchRequest.entity = entity

        do {
            guard let devices: [Device] = try context.executeFetchRequest(fetchRequest) as? [Device]
                where devices.count == 1
                else {
                    Constants.Log.error("Apikey not found in database (unexpected result!)")
                    return nil
            }
            let key = devices[0].apiKey
            return key
        } catch {
            Constants.Log.error("Apikey not found in database (unexpected result!)")
        }
    }
    return nil
}

I'm quite lost. It's telling me about the release of an object not being correct. I'm lost. Do you maybe know what i could do to fix this? I'm using Swift.

Invalid concurrent access to managed object calling 'release'; Stacktrace: (
0 x App 0x00549a71 ValidateConcurrency + 228
1 x App 0x005497b7 CustomSubclassRelease + 18
2 x App 0x00265ad4 TFC8x_App6DevicecfMS0_FT6entityCSo19NSEntityDescription30insertIntoManagedObjectContextGSqCSo22NSManagedObjectContext__S0 + 264
3 x App 0x00265bc8 TToFC8x_App6DevicecfMS0_FT6entityCSo19NSEntityDescription30insertIntoManagedObjectContextGSqCSo22NSManagedObjectContext__S0 + 100
4 CoreData 0x220bbf2b + 154
5 CoreData 0x220bad27 + 158
6 CoreData 0x220cc2d1 + 396
7 CoreData 0x22144527 + 766
8 CoreData 0x22144a99 + 324
9 CoreData 0x22146db3 + 66
10 libdispatch.dylib 0x01dc3f51 _dispatch_barrier_sync_f_slow_invoke + 564
11 libdispatch.dylib 0x01db6c83 _dispatch_client_callout + 22
12 libdispatch.dylib 0x01dbb76d _dispatch_main_queue_callback_4CF + 1680
13 CoreFoundation 0x209773fd + 8
14 CoreFoundation 0x209758f7 + 1574
15 CoreFoundation 0x208c8bf9 CFRunLoopRunSpecific + 520
16 CoreFoundation 0x208c89e5 CFRunLoopRunInMode + 108
17 GraphicsServices 0x21b14ac9 GSEventRunModal + 160
18 UIKit 0x24b58ba1 UIApplicationMain + 144
19 x App 0x00344ed4 main + 164
20 libdyld.dylib 0x20577873 + 2
)

EXC_BAD_ACCESS in CreateCustomSubclass

On running my app with this pod installed, I get an EXC_BAD_ACCESS in the CreateCustomSubclass method. A screenshot of the debug state at this point is attached. The variable 'class' comes in to the method fine, but something goes wrong and I'm not sure why. class_getName produces the same EXC_BAD_ACCESS if I try and add debug logging.

screen shot 2017-04-03 at 6 21 26 pm

Invalid concurrent access to managed object calling 'release'; on recursive saving of context

Hi,
I am using a helper function to save context recursively and my code looks like following snippet. When I added GDCoreDataConcurrencyDebugging to my workspace it keep showing "Invalid concurrent access to managed object calling 'release'; Stacktrace" whenever a save happens to the context. Could you please let me what is going wrong in the following snippet. I added "-com.apple.CoreData.ConcurrencyDebug 1" and this concurrency issue is not getting captured with the argument.

  • (void) saveManagedObjectContext:(NSManagedObjectContext *)managedObjectContext
    withCompletion:(void (^)(NSError * saveError))completion {

    [managedObjectContext performBlock:^{
    NSError *error = nil;
    if (![managedObjectContext save:&error]){
    if (completion) {
    completion(error);
    }
    } else {
    if ([managedObjectContext parentContext] != nil){
    [CoreDataController saveManagedObjectContext:[managedObjectContext parentContext] withCompletion:completion];
    } else {
    if (completion) {
    completion(error);
    }
    }
    }
    }];
    }

Invalid concurrent access to managed object calling 'release'; Stacktrace: (
0 SampleApp 0x0033ee45 ValidateConcurrency + 366
1 SampleApp 0x0033eb2a CustomSubclassRelease + 23
2 CoreData 0x0109cd3d -[NSSQLConstantValueIntermediate dealloc] + 45
3 libobjc.A.dylib 0x043d6060 _ZN11objc_object17sidetable_releaseEb + 238
4 libobjc.A.dylib 0x043d7320 -[NSObject release] + 25
5 CoreData 0x0109c15a -[NSSQLIntermediate _generateSQLForConstantValue:inContext:] + 122
6 CoreData 0x010a88ce -[NSSQLIntermediate _generateSQLForConstantCollection:inContext:] + 334
7 CoreData 0x010a80ad -[NSSQLSimpleWhereIntermediate _generateSQLContainmentStringInContext:] + 1821
8 CoreData 0x01099b56 -[NSSQLSimpleWhereIntermediate generateSQLStringInContext:] + 582
9 CoreData 0x01098f46 -[NSSQLFetchIntermediate generateSQLStringInContext:] + 118
10 CoreData 0x011c943a -[NSSQLGenerator newSQLStatementForRequest:ignoreInheritance:countOnly:nestingLevel:nestIsWhereScoped:] + 522
11 CoreData 0x010942f9 -[NSSQLGenerator newSQLStatementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:nestIsWhereScoped:] + 73
12 CoreData 0x011aa32a -[NSSQLAdapter _statementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:] + 442
13 CoreData 0x01094168 -[NSSQLAdapter _newSelectStatementWithFetchRequest:ignoreInheritance:] + 392
14 CoreData 0x01093fd0 -[NSSQLAdapter newSelectStatementWithFetchRequest:] + 48
15 CoreData 0x01093d52 -[NSSQLCore newRowsForFetchPlan:] + 130
16 CoreData 0x0109354d -[NSSQLCore objectsForFetchRequest:inContext:] + 573
17 CoreData 0x01092ebf -[NSSQLCore executeRequest:withContext:error:] + 591
18 CoreData 0x01199750 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 5120
19 CoreData 0x011a3fff gutsOfBlockToNSPersistentStoreCoordinatorPerform + 191
20 libdispatch.dylib 0x05de89cd _dispatch_client_callout + 14
21 libdispatch.dylib 0x05dcaada _dispatch_barrier_sync_f_invoke + 156
22 libdispatch.dylib 0x05dca242 dispatch_barrier_sync_f + 98
23 CoreData 0x01192ac7 _perform + 183
24 CoreData 0x01092a1f -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 431
25 CoreData 0x01090e69 -[NSManagedObjectContext executeFetchRequest:error:] + 649
26 CoreData 0x01169408 __92-[NSManagedObjectContext(_NSInternalChangeProcessing) _prefetchObjectsForDeletePropagation:]_block_invoke + 200
27 CoreFoundation 0x04d65839 ____NSDictionaryEnumerate_block_invoke417 + 41
28 CoreFoundation 0x04c482c2 CFBasicHashApply + 130
29 CoreFoundation 0x04c85321 __NSDictionaryEnumerate + 273
30 CoreFoundation 0x04c8518d -[NSDictionary enumerateKeysAndObjectsWithOptions:usingBlock:] + 45
31 CoreFoundation 0x04c850d5 -[NSDictionary enumerateKeysAndObjectsUsingBlock:] + 53
32 CoreData 0x01169298 -[NSManagedObjectContext(_NSInternalChangeProcessing) _prefetchObjectsForDeletePropagation:] + 296
33 CoreData 0x010df6c1 -[NSManagedObjectContext(_NSInternalChangeProcessing) _processDeletedObjects:] + 1217
34 CoreData 0x010c2f67 -[NSManagedObjectContext(_NSInternalChangeProcessing) _propagatePendingDeletesAtEndOfEvent:] + 119
35 CoreData 0x010bdd2a -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:] + 2010
36 CoreData 0x010bd536 -[NSManagedObjectContext processPendingChanges] + 54
37 CoreData 0x010e775e -[NSManagedObjectContext(_NestedContextSupport) _parentProcessSaveRequest:inContext:error:] + 2014
38 CoreData 0x0116c6fc __82-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke + 412
39 CoreData 0x010e1c5c internalBlockToNSManagedObjectContextPerform + 76
40 libdispatch.dylib 0x05de89cd _dispatch_client_callout + 14
41 libdispatch.dylib 0x05dcaada _dispatch_barrier_sync_f_invoke + 156
42 libdispatch.dylib 0x05dca242 dispatch_barrier_sync_f + 98
43 CoreData 0x010e1b7e _perform + 206
44 CoreData 0x010e19ce -[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:] + 238
45 CoreData 0x010c24e3 -[NSManagedObjectContext save:] + 1379
46 SampleApp 0x00240073 __59+[CoreDataController saveManagedObjectContext:withCompletion:]_block_invoke + 53
47 CoreData 0x010e170a developerSubmittedBlockToNSManagedObjectContextPerform + 202
48 libdispatch.dylib 0x05de89cd _dispatch_client_callout + 14
49 libdispatch.dylib 0x05dcdf90 _dispatch_main_queue_callback_4CF + 910
50 CoreFoundation 0x04cb85fe CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 14
51 CoreFoundation 0x04c762f4 __CFRunLoopRun + 2356
52 CoreFoundation 0x04c75706 CFRunLoopRunSpecific + 470
53 CoreFoundation 0x04c7551b CFRunLoopRunInMode + 123
54 GraphicsServices 0x0650d664 GSEventRunModal + 192
55 GraphicsServices 0x0650d4a1 GSEventRun + 104
56 UIKit 0x021071eb UIApplicationMain + 160
57 SampleApp 0x000f1657 main + 336
58 libdyld.dylib 0x05e12a21 start + 1
59 ??? 0x00000003 0x0 + 3
)

False positive with ALAssetsLibrary

When using ALAssetsLibrary, I'm seeing an "Invalid concurrent access to managed object calling 'release":

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
    // code
}];

It seems this may be a false positive? It looks like the Apple code may be creating the ALAssetsGroup on another thread, and this warning comes when it is released on the main thread.

Missing dependencies

I got a bad access exception at the line "DISPATCH_BLOCK_WRAPPER(dispatch_sync);" that stopped me from using this.

However I thought I'd mention that the dependencies of JRSwizzle and fishook.h aren't mentioned in your instructions.

I'm running Xcode 5.0.2, against iOS 7, I marked all the various dependencies of GDCoreDataConcurrencyDebugging for arc etc.

Nested context concurrency issue false positive on 'release'?

Thanks for this component, it has helped me heaps finding issues in my code!
I have recently been implementing a method for nested contexts described in the following article

I am pretty sure I am performing operations in performBlock of the right context but I get a lot of of "Invalid concurrent access to managed object calling 'release'; Stacktrace: "

At first I thought my implementation was incorrect but I found this sample implementation of the same methodology and when adding GDCoreDataConcurrencyDebugging I get the very same errors everything looks right to me.

Could this be a false positive in GDCoreDataConcurrencyDebugging?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.