好的,所以我有一个运行相当标准的CoreData + MagicalRecord堆栈的应用程序。它有以下之一:
MagicalRecord.setupCoreDataStackWithAutoMigratingSqliteStoreAtURL(whisperStoreURL)
要对我们的CoreData模型执行操作,我们会做两件事。
这一切都很好,除了生产中的大型崩溃,下面的堆栈跟踪。它似乎发生好像我违反了CoreData多线程规则,除非据我所知,我不是。对象/上下文永远不会在线程之间传递。
当打开CoreData并发调试时,在我们的本地计算机上,我们有时会遇到多线程违规(AllThatIsLeftToUsIsHonor),但它并没有特别指出任何原因。这可能是相关的,也可能不是。
我还尝试插入https://github.com/GrahamDennis/GDCoreDataConcurrencyDebugging以查看它是否提供了有关并发冲突的更多有用信息。它抛出了很多关于release
在与创建对象的队列不同的队列上调用的错误,但显然这是误报。
我甚至不确定“声明仍然有效”是什么意思。谷歌搜索它似乎与多线程问题有关,但我99%肯定我们没有违反任何规则。
我很确定有多个MagicalRecord块可以同时处理这些事情应该不是问题。在我的应用程序中,一个NSOperation可能正在保存一些东西,而另一个线程上的另一个块也保存了一些东西,而主线程本身可能正在写入默认上下文并使用MR_saveToPersistentStoreAndWait保存它。
我应该提一下,由于最近移植到MagicalRecord的遗留代码,在主线程上有很多调用MR_saveToPersistentStoreAndWait的东西还没有被移动到后台线程。这个工作正常,直到最近发布的内容显着增加了代码库中MagicalRecord / CoreData的数量。
除了推动模糊尝试将问题解决到生产之外,我已经没有其他事情需要调查。任何有关如何正确诊断多线程问题的建议都将受到赞赏。
崩溃的堆栈(在后台线程中)如下所示:
Fatal Exception: NSInternalInconsistencyException
statement is still active
Thread : Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x1844d1900 __exceptionPreprocess
1 libobjc.A.dylib 0x183b3ff80 objc_exception_throw
2 CoreData 0x185f32fbc -[NSSQLiteStatement cachedSQLiteStatement]
3 CoreData 0x185f327e4 -[NSSQLiteConnection prepareSQLStatement:]
4 CoreData 0x185f43020 -[NSSQLChannel selectRowsWithStatement:]
5 CoreData 0x18604534c newFetchedRowsForFetchPlan_MT
6 CoreData 0x185f3a7e4 -[NSSQLCore objectsForFetchRequest:inContext:]
7 CoreData 0x185f3a218 -[NSSQLCore executeRequest:withContext:error:]
8 CoreData 0x186001910 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke
9 CoreData 0x186009d58 gutsOfBlockToNSPersistentStoreCoordinatorPerform
10 CoreData 0x185ffc5c8 _perform
11 CoreData 0x185f39e70 -[NSPersistentStoreCoordinator executeRequest:withContext:error:]
12 CoreData 0x185f38938 -[NSManagedObjectContext executeFetchRequest:error:]
13 CoreData 0x185fda318 -[NSManagedObjectContext(_NestedContextSupport) _parentObjectsForFetchRequest:inContext:error:]
14 CoreData 0x185fdaa44 __82-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke
15 CoreData 0x185fcc76c _perform
16 CoreData 0x185fda824 -[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]
17 CoreData 0x185f38938 -[NSManagedObjectContext executeFetchRequest:error:]
18 whisper 0x1003bd5bc __67+[NSManagedObject(MagicalRecord) MR_executeFetchRequest:inContext:]_block_invoke (NSManagedObject+MagicalRecord.m:54)
19 CoreData 0x185fd1080 developerSubmittedBlockToNSManagedObjectContextPerform
20 CoreData 0x185fd0f48 -[NSManagedObjectContext performBlockAndWait:]
21 whisper 0x1003bd500 +[NSManagedObject(MagicalRecord) MR_executeFetchRequest:inContext:] (NSManagedObject+MagicalRecord.m:50)
22 whisper 0x1003bd794 +[NSManagedObject(MagicalRecord) MR_executeFetchRequestAndReturnFirstObject:inContext:] (NSManagedObject+MagicalRecord.m:77)
23 whisper 0x1003bba84 +[NSManagedObject(MagicalFinders) MR_findFirstByAttribute:withValue:inContext:] (NSManagedObject+MagicalFinders.m:107)
24 whisper 0x1003bbdfc +[NSManagedObject(MagicalFinders) MR_findFirstOrCreateByAttribute:withValue:inContext:] (NSManagedObject+MagicalFinders.m:150)
25 whisper 0x10023325c specialized FetchWhispersForFeedResponseProcessor.processWhispers([String : AnyObject]) -> () (FetchWhispersForFeedResponseProcessor.swift:107)
26 whisper 0x100232250 FetchWhispersForFeedResponseProcessor.processStatusCode200() -> () (FetchWhispersForFeedResponseProcessor.swift:76)
27 whisper 0x10023199c FetchWhispersForFeedResponseProcessor.processWithLocalContext(NSManagedObjectContext) -> () (FetchWhispersForFeedResponseProcessor.swift:22)
28 whisper 0x100222d20 CoreDataResponseProcessor.(main(CoreDataResponseProcessor) -> () -> ()).(closure #1) (CoreDataResponseProcessor.swift:15)
29 whisper 0x1003b6144 __47+[MagicalRecord(Actions) saveWithBlockAndWait:]_block_invoke (MagicalRecord+Actions.m:48)
30 CoreData 0x185fd1080 developerSubmittedBlockToNSManagedObjectContextPerform
31 libdispatch.dylib 0x183f255f0 _dispatch_client_callout
32 libdispatch.dylib 0x183f3089c _dispatch_barrier_sync_f_invoke
33 CoreData 0x185fd0f68 -[NSManagedObjectContext performBlockAndWait:]
34 whisper 0x1003b60ac +[MagicalRecord(Actions) saveWithBlockAndWait:] (MagicalRecord+Actions.m:44)
35 whisper 0x100222a58 CoreDataResponseProcessor.main() -> () (CoreDataResponseProcessor.swift:16)
36 whisper 0x100222b9c @objc CoreDataResponseProcessor.main() -> () (CoreDataResponseProcessor.swift)
37 Foundation 0x184dbb348 -[__NSOperationInternal _start:]
38 Foundation 0x184e7a728 __NSOQSchedule_f
39 libdispatch.dylib 0x183f255f0 _dispatch_client_callout
40 libdispatch.dylib 0x183f31634 _dispatch_queue_drain
41 libdispatch.dylib 0x183f290f4 _dispatch_queue_invoke
42 libdispatch.dylib 0x183f33504 _dispatch_root_queue_drain
43 libdispatch.dylib 0x183f33224 _dispatch_worker_thread3
44 libsystem_pthread.dylib 0x184139470 _pthread_wqthread
45 libsystem_pthread.dylib 0x184139020 start_wqthread