mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
iOS 10: Sectioned ListMonitor crashing with EXC_BAD_ACCESS #85
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jamesbebbington on GitHub (Sep 22, 2016).
Since upgrading to CoreStore v2.1.0 and Xcode 8 I'm getting a repeatable crash whenever I try to display a view that is backed by a sectioned
ListMonitoron the iOS 10 simulator (it's fine on iOS 9):If I change the monitor to a non-sectioned list it's fine.
I've tried enabling Zombie Objects but nothing helpful is logged.
Also, why is CoreStore warning me that I'm overwriting a
Whereclause? Isn't that the point ofrefetch()anyway?I'm at a bit of a loss at how to fix this one, any help would be much appreciated.
@JohnEstropia commented on GitHub (Sep 23, 2016):
Just to make sure, is this view controller your app's and storyboard's initial view controller?
I asked because there's a current trap where initial view controllers gets initialized before
application(_:didFinishLaunchingWithOptions:), which is probably before your storage gets added to the stack. (Although you mentioned it's fine if you use non-sectioned monitors)If that's not the case, I'll try to investigate. Thanks for the report!
@jamesbebbington commented on GitHub (Sep 23, 2016):
Thanks @JohnEstropia. No, this isn't my initial view controller.
@JohnEstropia commented on GitHub (Sep 23, 2016):
Your EXC_BAD_ACCESS indicates
EXC_I386_GPFLT, and your simulator is iPhone 5s, which leads me to believe that there is a 32-bit-related problem somewhere. Maybe a property which yourSectionBy("id")relies on? Maybe tryinstead of
@JohnEstropia commented on GitHub (Sep 23, 2016):
Oh oops, it turns out EXC_I386_GPFLT has nothing to do with floats, but
General Protected Fault, which has more to do with accessing invalid memory (zombies)@jamesbebbington commented on GitHub (Sep 23, 2016):
Yeah, my
idproperty is already declared as anNSNumber.N.B. I'm actually grouping by a related model, but I changed it to
idas you see above, to see if that was causing the crash.@JohnEstropia commented on GitHub (Sep 23, 2016):
Hmm... Can you put an Exception Breakpoint and see where the error was thrown from?
@jamesbebbington commented on GitHub (Sep 23, 2016):
No difference, I'm afraid:
@JohnEstropia commented on GitHub (Sep 23, 2016):
One last thing I can think of, do all your relationships have inverse relationships?
If that's not it either then I have no leads right now... Can you isolate the crash in a smaller project? (maybe using CoreStore's demo app)
@jamesbebbington commented on GitHub (Sep 23, 2016):
Yeah, just checked and can't see anything wrong with them.
That was my original plan when filing this ticket - I've attempted to created a stand-alone minimal test case app that exhibits this crash but I haven't managed to replicate it unfortunately.
@laeroah commented on GitHub (Sep 23, 2016):
I have this issue too. Only happens on iOS10.
@laeroah commented on GitHub (Sep 23, 2016):
Crash log:
@jamesbebbington commented on GitHub (Sep 23, 2016):
Sorry to hear it's biting you too @laeroah.
I said:
Here's my attempt at creating a minimal test case. @laeroah perhaps you can replicate the crash on that app?
@laeroah commented on GitHub (Sep 23, 2016):
Ok, I think I can reproduce the issue:
In
CountriesTableViewControllerchange the monitorSectionedList part to:Crashes every time.
@JohnEstropia commented on GitHub (Sep 23, 2016):
Wow, awesome detective work guys, thanks :)
So the problem is with fetchBatchSize? If so this sounds like an iOS 10 bug :( I'll try to find a workaround (if i can also reproduce it)
@laeroah commented on GitHub (Sep 23, 2016):
thank you!
seems putting anything inside
Tweakwill crash. Not just fetchBatchSize. One property I really need to set isincludesSubentities, so anyway to do that around without using Tweak clause?@JohnEstropia commented on GitHub (Sep 23, 2016):
Huh, It doesn't crash on my side with @jamesbebbington's repo and @laeroah's edit...
@jamesbebbington commented on GitHub (Sep 23, 2016):
It does for me.
And I'm not
Tweaking in my example:@JohnEstropia commented on GitHub (Sep 23, 2016):
nevermind, I just reproduced the crash (weird, it happens only on second execution)
@JohnEstropia commented on GitHub (Sep 23, 2016):
I might have a hunch on why this is happening. Let me test for a while
@JohnEstropia commented on GitHub (Sep 23, 2016):
My hunch was correct, but I hit a roadblock. First, using @jamesbebbington's test project, go to CoreStoreFetchRequest.swift and comment out the override for
affectedStoresThis fixed the crash for me. Here's the problem: doing this breaks CoreStore's unit tests and demo app. The difference I can think of is that the test project imports CoreStore as a Cocoapod, and CoreStore's test cases and demo app imports it as a framework. There must be a Cocoapod compiler setting somewhere that somehow fixes the bug that
override var affectedStoreswas trying to fix.I'll continue investigating this tomorrow, but if you find other hints please do share. In the meantime, you can try commenting out the code above.
@laeroah commented on GitHub (Sep 23, 2016):
I can verify the workaround. Thank you so much.
@laeroah commented on GitHub (Sep 26, 2016):
@JohnEstropia hey, I'm a little confused about how the queues are handled.
In
beginAsynchronous, when the closure is performed, it is usingself.transactionQueue.async, and execute the closure in one serial queue "com.corestore.datastack.childtransactionqueue".Now, shouldn't the closure be performed in
performBlockof the transaction's managed context? since inside the closure, we suppose use the transaction to do stuff on managed objects in the transaction's context.I believe this is why multithread violation exception is being called by the xcode. I could be wrong, but hope this would be helpful information to fix the crashes.
Currently using CoreStore on a project, which has a tight deadline. :(
@JohnEstropia commented on GitHub (Sep 26, 2016):
@laeroah
There has been many inquiries regarding why CoreStore doesn't use the context's
performBlock:As explained in the previous threads, CoreStore manages the queueing on the architecture level (transactions), not on the data level (
performBlock). As such, debugging withcom.apple.CoreData.ConcurrencyDebugis really not required. This is explicitly mentioned in the README: https://github.com/JohnEstropia/CoreStore#installationAs for the crash in question, I assure you this has nothing to do with threading, but with a long standing bug with the
NSFetchRequest.affectedStoresproperty: http://stackoverflow.com/questions/14396375/nsfetchedresultscontroller-crashes-in-ios-6-if-affectedstores-is-specifiedCoreStore fixed this in pre-iOS 10 by subclassing NSFetchRequest, but with iOS 10 the previous workaround seems to not work anymore.
I understand this is affecting your project, but so far I haven't found a work around that fixes the bug. In the meantime, If you are just using
instead of
in your
Fromclauses, I can provide a temporary branch you can use with your project. I'll test if it runs fine on iOS 10 and notify you if it works as soon as I can.@JohnEstropia commented on GitHub (Sep 26, 2016):
@laeroah May I ask how you installed CoreStore in your project? Do you use Cocoapods?
If so, can you try to import CoreStore using Carthage or using git submodule and see if this crash still occurs?
I cannot reproduce this bug with Swift 2.3 projects that builds CoreStore's framework project so you might have some luck with it.
@jamesbebbington commented on GitHub (Sep 26, 2016):
@JohnEstropia said:
Yup, if I comment out the
affectedStoresoverride, my app no longer crashes.@JohnEstropia commented on GitHub (Sep 26, 2016):
@jamesbebbington You may need to check certain cases because there seem to be some cases where the fix above just propagates the crash to a different time. See https://github.com/JohnEstropia/CoreStore/issues/101
Please also try if importing CoreStore via Carthage or git submodule instead of Cocoapods can fix the problem for you.
@laeroah commented on GitHub (Sep 26, 2016):
@JohnEstropia I have tried copy all CoreStore and GCD code directly into a project, but still it crashes. I'm only using From(). Didn't use multiple configurations. thank you.
@JohnEstropia commented on GitHub (Sep 26, 2016):
@laeroah @jamesbebbington Sorry for the long wait! Please try the
developbranch if it fixes the problem for you.Workaround:
4d2ebe4ea8 (diff-5b788f6d8b8b55c6c042f1f510bf673cR234)@laeroah commented on GitHub (Sep 27, 2016):
worked! thanks!
@JohnEstropia commented on GitHub (Sep 27, 2016):
Whew, thats great :) Hopefully this bug won't bite us again in a future iOS update... Will update the master branch and the Cococapods trunk later within the day. (Please wait for version 2.1.1)
@laeroah and @jamesbebbington, thanks for all the feedback. It was a great help :)
@jamesbebbington commented on GitHub (Sep 27, 2016):
You're welcome @JohnEstropia. Thanks for the fix!
@laeroah commented on GitHub (Sep 27, 2016):
Thank you!
@a13xb commented on GitHub (Feb 27, 2019):
I am running into the exact same issue right now (Xcode 10.1, Swift 4, CoreStore 6.1, running on iOS 10). However any previous workarounds mentioned here appear to have been removed (
CoreStoreFetchRequestremoved entirely ineeec3979). Was there a rationale for this? (new workaround, no workaround necessary, something else)@JohnEstropia commented on GitHub (Feb 27, 2019):
@a13xb Hi, is your project and CoreStore being compiled as Swift 4.2? If not, please use the 5.x version for now and let me know if you still see the issues
@a13xb commented on GitHub (Feb 27, 2019):
Yes it's compiled with Swift 4.2. I'll give 5.x a shot.
@JohnEstropia commented on GitHub (Feb 28, 2019):
@a13xb Please let me know if 5.x works for you. As for the rationale of
eeec3979ee, I've had a suite of use-cases (Including https://github.com/JohnEstropia/CoreStore/issues/100#issuecomment-249223584) that broke without the workaround. With the latest Swift version I've found them working even without theCoreStoreFetchRequestworkaround so assumed it's been fixed.In that regard, it does mean the tests I've been doing until now are not reliable anymore so if anyone can provide an isolated case for this new issue It'd be a great help.
@a13xb commented on GitHub (Feb 28, 2019):
@JohnEstropia commented on GitHub (Feb 28, 2019):
Oh boy 😅
@a13xb Thanks for testing this out! I'll try to get a fix up in the next update
@JohnEstropia commented on GitHub (Feb 28, 2019):
@a13xb Reverted some changes in CoreStore 6.2.0. Let me know if there are further issues
@a13xb commented on GitHub (Feb 28, 2019):
Still the same crash, unfortunately.
I have tested with
5b365c64(one beforeeeec397), and it does not crash, which leads me to believe it's regressed precisely ineeec397(the removal ofCoreStoreFetchRequest).@JohnEstropia commented on GitHub (Feb 28, 2019):
@a13xb Please try the latest
developbranch and let me know how it goes@a13xb commented on GitHub (Feb 28, 2019):
Yep, that fixes it. 👍
@JohnEstropia commented on GitHub (Feb 28, 2019):
Updated as
6.2.1@a13xb commented on GitHub (Feb 28, 2019):
Works like a charm. Thanks for the prompt fix.