Skip to content
New issue

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

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

Already on GitHub? # to your account

"API Misuse" error during removePersistentStore: on macOS 11 #16

Closed
evanmiller opened this issue Sep 25, 2020 · 4 comments
Closed

"API Misuse" error during removePersistentStore: on macOS 11 #16

evanmiller opened this issue Sep 25, 2020 · 4 comments

Comments

@evanmiller
Copy link

When closing a document on Big Sur, I'm seeing the following errors:

CoreData: error:  API Misuse: Attempt to serialize store access on non-owning coordinator (PSC = 0x60000280f330, store PSC = 0x0)
CoreData: error: Mutating a managed object 0xc250978243fac5d5 <x-coredata://5BBC5881-6BFB-47F0-817F-B6217A748A93/DSDataRoot/p1> (0x6000020505f0) after it has been removed from its context.

The error occurs on this line:

result = [_coordinator removePersistentStore:_store error:&error];

It is sometimes followed by a crash during dealloc but I need to investigate that some more. I don't see the errors on earlier operating systems.

@jerrykrinock
Copy link
Owner

I have seen that error occur, but not recently, and I have been testing my apps, which are non-ARC, pretty much every day on Big Sur since June. I just retested some document closings now, with Beta 8. The line of code you mentioned executes with no errors. Are you seeing the errors with your app, or with BSTestApp? ARC or not?

@evanmiller
Copy link
Author

non-ARC, my own app.

The "Mutating" error seems to crop up after releasing (deallocating) a managed object fetched from the store (my "Data Root" object) and then doing any kind of operation on the store, including processPendingChanges and removePersistentStore:. I'll need to do some more investigating on this end. I could have a logic error.

Incidentally, one thread I saw said that their errors went away by migrating to NSPersistentContainer, introduced in 10.12. This might be an avenue for simplifying things in the future.

@evanmiller
Copy link
Author

Update: A second app of mine does not have this issue. After further investigation, I traced the problem to a key-value observer on the managed objects. Oddly, I was removing the observer prior to releasing the objects and prior to calling [super close], but something behind the scenes must have been confused because I still saw KVO-type errors later (perhaps the removal is somehow asynchronous in Big Sur?).

In any event, removing the KVO code altogether seems to have fixed the problem. KVO has caused nothing but problems in my code base so I will be happy to say good riddance to it.

I'll leave this issue open for the rest of the day in case the error message crops up again.

@evanmiller
Copy link
Author

Okay, removing KVO fixed this error in a couple of different builds, so I will chalk it up to a Core Data Mystery and close the issue.

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

No branches or pull requests

2 participants