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

Fixed multi-threading crash when copying a store #69

Merged
merged 1 commit into from
Feb 28, 2022
Merged

Fixed multi-threading crash when copying a store #69

merged 1 commit into from
Feb 28, 2022

Conversation

sgruby
Copy link
Contributor

@sgruby sgruby commented Feb 25, 2022

When the store is a .directory type and public func copy(to targetURL: URL) throws is called, the copy in that method is performed on the backgroundContext. In the private func copy(to targetURL: URL, tempURL: URL, blobs: BlobStore) that is called, the manifest is created using LoggerStoreInfo which calls try messageCount() and try networkRequestsCount(). Both of these methods do their fetch using container.viewContext which is a different thread leading to a crash.

You can verify the crash by using the com.apple.CoreData.ConcurrencyDebug 1 runtime flag (see [https://oleb.net/blog/2014/06/core-data-concurrency-debugging/](Core Data Concurrency Debugging) and then exporting the LoggerStore.

By getting the counts on the same thread, this crash is eliminated.

@sgruby sgruby closed this Feb 25, 2022
@sgruby sgruby reopened this Feb 25, 2022
@kean
Copy link
Owner

kean commented Feb 28, 2022

Thanks for the fix. I'm merging and pushing a patch now.

@kean kean merged commit d6f5659 into kean:master Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants