Skip to content

[WIP] Move the database from the AppGroup to main app Documents directory (OLD) #415

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

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

mpretty-cyro
Copy link
Collaborator

The iOS app has had a long standing crash related to the database, the app crashes with the error code 0xdead10cc (or “Deadlock”) and it happens when the app goes into a “suspended” state whilst it still maintains a lock on the database. We've tried a number of times to resolve this issue without a large structural change but, while we seem to have reduced the frequency, we've been unable to entirely resolve it.

While the above describes the situation where this crash occurs there is one other important piece of information - this crash can only occur if the database is stored within the “AppGroup” directory (this is a shared directory that the main app, notification extension and share extension all have access to). When there is a database file in this location the OS will put a lock on the file to ensure two processes can’t access it at the same time and, when one process goes into the “suspended” state, the OS will throw a 0xdead10cc error when the process hasn’t properly shut down the database access.

Annoyingly this crash doesn’t occur at all on the simulator and may not occur on debug builds, we also have no good way to intentionally replicate the crash because the OS decides when the app goes into a “suspended” state (we can try to force it by going into the background while there is an open database transaction by just making the transaction thread “sleep” for more than ~30s but it doesn’t work all the time, and isn't exactly the same crash 😞)

  • Note: The approach above to cause the crash will only occur if a write has already occurred within the transaction, otherwise it’s able to just discard the transaction without issue

The purpose of this PR is to move the database file from the “AppGroup” into the main app directory where the OS will no longer need to put a lock on the file, and as a result the 0xdead10cc should no longer be possible.

• Removed some duplicate code
• Added xchacha20 encrypt/decrypt functions
• Added code to move the database from the AppGroup to the main app Documents directory
• Added code to store the required user metadata in the AppGroup in encrypted form
• Added code to replicate the config dumps to the AppGroup in encrypted form
• Added code to update the "replicated" config dumps when they change
• Started updating the share extension UI to be driven solely via config data
@mpretty-cyro mpretty-cyro self-assigned this Apr 4, 2025
@mpretty-cyro mpretty-cyro changed the title [WIP] Move the database from the AppGroup to main app Documents directory [WIP] Move the database from the AppGroup to main app Documents directory (OLD) May 5, 2025
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.

1 participant