Skip to content

Fix a CoreData multithreading issue in LoggerStore.info()#293

Merged
kean merged 1 commit intokean:mainfrom
ejensen:core-data-threading-issue
Sep 19, 2024
Merged

Fix a CoreData multithreading issue in LoggerStore.info()#293
kean merged 1 commit intokean:mainfrom
ejensen:core-data-threading-issue

Conversation

@ejensen
Copy link
Contributor

@ejensen ejensen commented Sep 19, 2024

LoggerStore.info() uses NSPersistentContainer.performBackgroundTask to construct the info. The background task constructs has its now NSManagedObjectContext that must be used throughout the task.

However getBlobsSize() was using a different backgroundContext to fetch the sum of the blob size. This mismatch of contexts causes a CoreData multithreading assertion to be triggered.

This PR addresses this issue by supplying the correct NSManagedObjectContext to use within getBlobsSize()

The store info is constructed using a background task. The background task constructs its own context that needs to be used throughout the task
@kean kean merged commit 2380f56 into kean:main Sep 19, 2024
@kean
Copy link
Owner

kean commented Sep 19, 2024

Great catch, thank you!

@ejensen ejensen deleted the core-data-threading-issue branch October 9, 2024 01:39
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.

2 participants