project-imas / encrypted-core-data

v2.0 - iOS Core Data encrypted SQLite store using SQLCipher
Other
785 stars 236 forks source link

Concurrency issue when performFetch: and a background context are reading/writing on the same entities #247

Closed idcuesta closed 6 years ago

idcuesta commented 8 years ago

Description

I am currently using Encrypted Core Data in a project, and I am experiencing a concurrency issue.

My project has a Core Data Stack like this one 1-6ufmw_viglltpujlfqnkjg

Under this scenario I get random deadlocks when a performFetch: from my NSFetchedResultsController happens at the same time the Private Queue Context is reading/writing from the same entities.

I have also tried to follow recommendations from Core Data Performance Optimization and Debugging video from WWDC 2013 and make my Private Queue Context and Main Queue Context use their own Persistence Store Coordinators, but when doing that I constantly get this error from save operations Error Domain=NSSQLiteErrorDomain Code=5 "(null)" UserInfo={EncryptedStoreErrorMessage=database is locked}.

When using a default store (non encrypted) there are no deadlocks and everything works fine.

I have added some unit tests that demonstrate the 3 different behaviors for each Core Data Stack. Different Core Data Stacks are running exactly the same tests and the results are:

Tests for the default SQLite Store

idcuesta commented 8 years ago

I have submitted a PR with the unit tests -> #246

ppaulojr commented 8 years ago

👍 I'm experiencing the exact same problem!

idcuesta commented 6 years ago

Closing this due to inactivity