[WIP] Move the database from the AppGroup to main app Documents directory (OLD) #415
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 😞)
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.