Skip to content
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

Closed
kalmeshnfk opened this issue Oct 1, 2018 · 12 comments
Closed

Crash : Realm Open Failed #5938

kalmeshnfk opened this issue Oct 1, 2018 · 12 comments

Comments

@kalmeshnfk
Copy link

kalmeshnfk commented Oct 1, 2018

Actual Results

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

  • No clear steps to reproduce this

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

@tgoyne
Copy link
Member

tgoyne commented Oct 1, 2018

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?

@kalmeshnfk
Copy link
Author

The path is something like this /var/mobile/Containers/Data/Application/xxxxxxxx/Documents/default.realm.lock

@kalmeshnfk
Copy link
Author

And yes, its on startup based on breadcrumbs reported.

@kalmeshnfk
Copy link
Author

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.

@litso
Copy link

litso commented Nov 12, 2018

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.

@theonetheycallneo
Copy link

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.

@litso
Copy link

litso commented Nov 16, 2018

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 realmFile in the realm config.

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 .none on your app's Documents directory does nothing.

@sravich
Copy link

sravich commented Jan 23, 2019

@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

@litso
Copy link

litso commented Jan 23, 2019

@sravich it would happen under these circumstances. we were able to detect app being launched from location updates via logging #5938 (comment)

@stennie stennie added the T-Bug label Sep 29, 2019
@stennie
Copy link
Contributor

stennie commented Sep 29, 2019

Closing this issue due to no recent activity. Please comment if you have additional information that may help reproduce this issue.

@stennie stennie closed this as completed Sep 29, 2019
@benski
Copy link

benski commented Oct 1, 2019

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
We have hypothesized that it is due to a combination of data privacy lockdown (File Protection) and Background Refresh.
The Realm documentation mentions a workaround, but we have not yet implemented it because we will have to migrate our existing databases to a new directory.

@joaopdcgarcia
Copy link

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 We have hypothesized that it is due to a combination of data privacy lockdown (File Protection) and Background Refresh. The Realm documentation mentions a workaround, but we have not yet implemented it because we will have to migrate our existing databases to a new directory.

@benski Did you end up migrating to a new directory?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants