project-imas / encrypted-core-data

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

Concurrency issue [reproduced through tests] #246

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

ppaulojr commented 8 years ago

This unit test is designed to fail current version. So the fact it fails is a very good sign to merge it!

ppaulojr commented 8 years ago

Hey folks, if you could merge this one that would be super helpful to solve this ugly deadlock problem.

DanielBroad commented 8 years ago

I understand this doesn't fix any issue, it just introduces a failing test?

ppaulojr commented 8 years ago

Yes, that's the idea of this PR. We are noticing this deadlock problem and the tests are an easy way to reproduce it and assist the process of fixing it.

In the meantime I'm investigating the problem in EncryptedCoreData source so I can make a PR fixing it too.

idcuesta commented 6 years ago

We finally migrated to a different encryption solution (Realm).

I am closing this as it seems it is not useful.