-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Crash when device is locked #1260
Comments
There isn't really any way to gracefully fail when the file isn't readable. Since nearly every method in our API could fail, all we could really do is throw an exception instead, which would still be a fatal error. Making every single method take an You can control whether or not files get locked when the device is locked by changing the value of |
While I agree that it is difficult to deal with the fact that all of these operations are fundamentally failable—and with the current API dealing with this would be a challenge—I feel it is still not appropriate that something as common as a read or write error is a fatal and unrecoverable error which will bring down an entire application. I've actually implemented your suggestion of changing the Stack trace
|
In this stack trace we are throwing a c++ exception rather than returning an error when opening the Realm. In this case we should definitely be catching this exception and returning an NSError. |
I had the same issue in obj-c code: #1077 |
@kronik this does seem to be the same issue. I think we can make this work for the case @melbyruarus provided. If make things fail gracefully by properly returning an error when opening a Realm using the initializer with an output error, then users can at least detect and avoid crashing by getting a new Realm instance and checking the error before performing any potentially unsafe background operations. The ideal long term solution though would be to actually make things work in the background. |
It appears to me that we already catch any C++ exceptions inside |
@segiddins there are other core operations in the factory method which are not wrapped with an exception handler - these cases should also return an error from the factory methods. There is also the possibility that we are not catching the type of exception being thrown in this case as we may be missing some handers. |
Realm actually will fail gracefully as long as you use on of the factory methods that takes an error parameter (and a pointer to an @melbyruarus I hope this helps. |
Is there any way to read/write while device was locked ? |
You'll have to set |
@jpsim it seems that the parent directory advised to change |
Figured it out:
^ fyi, if you don't explicitly set it as the default realm, you may end up with the default.realm in addition to the realm in your new directory. This code also doesn't include creating the directory if it doesn't already exist. |
Also, fyi, using a subdirectory doesn't seem to work with |
Goal
Use Realm while the device is locked
Expected results
Realm will behave the same as it does when the device is not locked, or will fail gracefully if this is not possible.
Actual results
Calling any Realm method that will read/write data to the disk while the device is locked will cause the app to crash.
Steps to reproduce
Will require:
The app will then crash sometime later when iOS stops allowing access to encrypted data.
Code sample
https://github.com/melbyruarus/Realm-Background-Crash
The crash is triggered in the LocationHelper.log method
Discussion
I believe this occurs because if a PIN is set and the device is locked then shortly thereafter iOS throws away the decryption keys for files which are only accessible while the device is unlocked (the default?). This means that the Realm database file becomes inaccessible and gets a read/write/open error when accessed, and this error is not correctly handled.
Ideally there would either be a way to customise the creation of the database file so that it can be specified as not needing to be protected on lock, and additionally any read/write/opens should fail gracefully rather than exploding.
This may well be a duplicate of #773
Version info
iOS 8, Realm 0.89, Xcode 6.1.1
The text was updated successfully, but these errors were encountered: