-
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 : Realm Open Failed #5938
Comments
Is that path anonymized? The failing path is obviously not a valid one, so if it's accurate the problem is somehow related to getting the app's document directory. Crashlytics says the app is never in the background, so it's probably not an NSFileProtection-related issue. The stack trace sort of hints at it being the first start of the app (due to the signup/login VCs), and if that's actually the case then it might somehow be related to backup/restore setting weird permissions? Alternatively, is it possible that the crashing devices are ones with MDM profiles imposing odd restrictions? |
The path is something like this /var/mobile/Containers/Data/Application/xxxxxxxx/Documents/default.realm.lock |
And yes, its on startup based on breadcrumbs reported. |
This is not reported in our internal testing, but only in production, so pretty hard to tell if its only on devices running MDM or scenarios around backup/restore. |
We are seeing the same issue on an enterprise app deployed via MDM. In our case i believe the app is being launched in the background due to location updates, then crashing in the same place mentioned in this ticket. Any help would be greatly appreciated. |
We are seeing the same issue on about 10% of our users. We are thinking it's something to do with the Data Protection capability we have enabled. |
We were able to solve this issue by creating a separate directory for Realm and setting the file permissions on that directory. guard let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else {
fatalError("Could not access documents directory when setting up Realm")
}
let realmDirectoryPath = documentsDirectory.appendingPathComponent("Realm")
do {
// Disable file protection to allow Realm to be used during Background App Refresh.
// See https://realm.io/docs/swift/latest/#using-realm-with-background-app-refresh
try FileManager.default.createDirectory(atPath: realmDirectoryPath.path, withIntermediateDirectories: true, attributes: [.protectionKey: FileProtectionType.none])
} catch {
fatalError("Error creating directory: \(error.localizedDescription)")
}
let realmFile = realmDirectoryPath.appendingPathComponent("default.realm") We then specify This is partially documented here however the documentation really should stipulate that you have to set a custom path in a subdirectory because attempting to set file protection to |
@litso Do you have a reproduce the above issue. My issue is the same. I would love to try the fix you mentioned. But I have been unable to reproduce this crash that some of my users are facing |
@sravich it would happen under these circumstances. we were able to detect app being launched from location updates via logging #5938 (comment) |
Closing this issue due to no recent activity. Please comment if you have additional information that may help reproduce this issue. |
We are experiencing this issue on an app with a very large user base. It only effects 0.05% of our sessions, but it is our largest crash by far. It is not a user-facing crash |
@benski Did you end up migrating to a new directory? |
Actual Results
http://crashes.to/s/5c3c3ce8675
Error : Error Domain=io.realm Code=2 "Unable to open a realm at path '/var/mobile/Containers/Data/Application//Documents/default.realm.lock': open() failed: Operation not permitted." UserInfo={Error Code=2, NSFilePath=/var/mobile/Containers/Data/Application//Documents/default.realm.lock, Underlying=open("/var/mobile/Containers/Data/Application//Documents/default.realm.lock") failed: Operation not permitted, NSLocalizedDescription=Unable to open a realm at path '/var/mobile/Containers/Data/Application//Documents/default.realm.lock': open() failed: Operation not permitted.}
Steps to Reproduce
Code Sample
We have already tried this
#3308 (comment)
Version of Realm and Tooling
Realm framework version: 3.7.6
iOS/OSX version: across versions
The text was updated successfully, but these errors were encountered: