-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Error Domain=io.realm Code=2 "Unable to open a realm at path #6096
Comments
Any insights into what's going on here? We've been investigating this as a major crasher for our users. |
I don't really know anything past what the error says and the documentation that you found. The only Realm-specific detail is that "ApplicationData.realm.lock" is the first of several files that we try to open when you try to open "ApplicationData.realm", and the open() call is failing with |
@tgoyne thanks for jumping in! To give some more context: this is happening for users who previously had accessed this One thing that I forgot to mention previously is that we do add new Also to re-iterate, we don’t change the file system permissions on realm's configuration. This is the LOC where realm catches this exception:
Can you provide any pointers about any potential causes this could happen? |
We encounter frequent crashes on app startup. Actually it ranks as our most frequent crash right now. It's the same error message:
Crash on startup. With the following stack traces:
What particularly stands out is that the same realm file is accessed too, to fetch some other data:
Maybe this gives some more insights... |
I had the same problem, in my application has the possibility of the user log off and enter with another account, which generates another bank file of realm, the problem in my application happens when the user already has a database realm in the documents folder of the application and logs off, I imagine the realm problem has happened because realm is trying to access the primary database without having access to it. |
This is my highest crasher. Using realm 3.15.0. Has anyone found a good workaround, other than deleting the database (which I can't do)? |
Any update with this? Seeing the same problem here too |
Any solution to this? Becoming increasingly frequent! Using Realm 3.2.0
|
Same issue, I would be interested in a any solution to avoid this crash at the start of the app This appends in this function in the appDelegate
note that my error is slightly different Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=2 "Unable to open a realm at path '/var/mobile/Containers/Data/Application/80BDC8A5-A594-4F58-AC48-E4DBE11782D2/Documents/default.realm': Invalid streaming format cookie (35454533953) Path:." UserInfo={Error Code=2, NSFilePath=/var/mobile/Containers/Data/Application/80BDC8A5-A594-4F58-AC48-E4DBE11782D2/Documents/default.realm, Underlying=Invalid streaming format cookie (35454533953) Path: /var/mobile/Containers/Data/Application/80BDC8A5-A594-4F58-AC48-E4DBE11782D2/Documents/default.realm, NSLocalizedDescription=Unable to open a realm at path '/var/mobile/Containers/Data/Application/80BDC8A5-A594-4F58-AC48-E4DBE11782D2/Documents/default.realm': Invalid streaming format cookie (35454533953) Path:.}: file [path to a personal files??]/RealmHelper.swift, line 123 |
That code will fail catastrophically if the device is low on disk space: writeCopy() will create the file, write to it until the disk is full, then throw an error. We don't delete the incomplete file when writing fails, so the original file will then be replaced with the incomplete one and produce the error you're seeing. The fix for this would be to either handle the error thrown by writeCopy() and delete the temporary file, or use compact on launch which should handle all of the error cases safely. |
And so on |
The more easy thing to debug this things (because I get sigaborts without stacktrace) so either you need to write in debugger And when hit go one above the stack This was the better way to find the error for me... also you can add an If you know how to make this breakpoint catch a specific exception like |
I am also getting this error, the path the generated successfully but I cannot able to goto that particular location path and also the realm exception error was occur like "Unable to open a realm at path". this kind of was happening simultaneously..
`` |
I am also getting this error after updating the realm (since 2020 June 5) from 3.16.1 to 5.0.2. Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=2 "Unable to open a realm at path '/var/mobile/Containers/Data/Application/90D60EF8-D05F-459E-A517-E26FDEF9622A/Documents/default.realm.lock': open() failed: Operation not permitted Path: /var/mobile/Containers/Data/Application/90D60EF8-D05F-459E-A517-E26FDEF9622A/Documents/default.realm.lock Exception backtrace: 0 Realm 0x00000001053dd59c _ZN5realm4util4File13open_internalERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS1_10AccessModeENS1_10CreateModeEiPb + 712 1 Realm 0x000000010532e33c _ZN5realm2DB7do_openERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEbbNS_9DBOptionsE + 980 2 Realm 0x0000000105331544 _ZN5realm2DB4openERNS_11ReplicationENS_9DBOptionsE + 244 3 Realm 0x0000000105335a1c _ZN5realm2DB6createERNS_11ReplicationENS_9DBOptionsE + 392 4 Realm |
I have the same issue using realm 4.4.1 crash_info_entry_0 Crashed: com.apple.main-thread |
Any update on this issue? |
Our application has hundreds of thousands of users. This crash is the number 1 cause of crashes currently. For this to be going on for so long for so many people is unacceptable. Will be looking at moving off Realm to some alternative forever and never using Realm for current or any future products if the inability to fix this continues. !!!! REALM ERROR Initialization. 2 Error Domain=io.realm Code=2 "Unable to open a realm at path '/var/mobile/Containers/Data/Application/1726B833-4851-457B-A3CD-C80069C1BF66/Documents/default.realm': Realm file decryption failed Path:Exception backtrace: |
@mungbeans2 We are sorry that you are encountering this issue. In order for us to try get to the bottom of this Could you tell me what version of Realm you are using and also could you provide a code sample that shows how you are using Realm and maybe some context of how you are using it (AppGroups, Multithreading, Encryption etc). Thanks, |
Lee, thanks for the prompt reply. Will post some more info later. |
I am also facing the same issue and it is also the highest crasher for my application. |
I have also seen this error in CrashAnalytics and it was the only crash that was being reported in high volume. Could never reproduce using a Debug build and could never reproduce issue in-house just crash logs from customer usage. The best I can tell it happened after users upgraded our App even though the Realm version, and schema had not changed. The one change we did make in the App update was to reference a realm object in AppDelegate that we hadn't before. In other words we were accessing Realm a lot sooner than in the prior version. Previously the first access to Realm was when logging into web site which required user input so Realm access was not so quick. This made me suspect there was a timing race condition associated with the Realm file access since I could not reproduce with Debug build. I really want to use Realm in my future iOS projects, but this issue which has been occurring for 1.5 years for us makes me gun shy. I guess the other possibility is that iOS messed up the file system permissions for sandbox when doing our App update. |
I wonder if file permissions are getting messed up if user is updating your app from app store and realm is locked? |
I know it's not a complete solution but I've used two solutions in combination to eradicate the issue.
|
Having same problem but the error message is slightly different in my case.
|
having the same problem, any solution? |
@norio-agoop @zrx89757 Can you please share the full crash log and what version of Realm your are using? |
Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=2 "Unable to open a realm at path '/var/mobile/Containers/Data/Application/196168ED-146C-4398-935E-FB13A658DA9F/Documents/default.realm.lock': open() failed: Operation not permitted Path: /var/mobile/Containers/Data/Application/196168ED-146C-4398-935E-FB13A658DA9F/Documents/default.realm.lock Exception backtrace: 0 Realm 0x0000000103444638 _ZN5realm4util4File13open_internalERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS1_10AccessModeENS1_10CreateModeEiPb + 712 1 Realm 0x0000000103377eb8 _ZN5realm2DB7do_openERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEbbNS_9DBOptionsE + 2716 2 Realm 0x000000010337ac6c _ZN5realm2DB4openERNS_11ReplicationENS_9DBOptionsE + 244 3 Realm 0x000000010337f598 _ZN5realm2DB6createERNS_11ReplicationENS_9DBOptionsE + 392 4 Realm Facing frequently on app up |
@niralishaha25 are you using encryption? Does your app belong to an App Group? Have you got any file permissions set in your app? |
Is anyone able to answer Lee's two questions above? |
I am not using encryption. |
I am experiencing the exact same problem. I have never encountered this problem myself in a development environment for several months, only on end-user devices where the problem would occasionally appear.
From the crash logs, it appears that when the iOS 14 Widget (not main app) is launched (in The database files are always located in a fixed directory in the AppGroup. Following is the launch code of my widget extension: @main
struct MyWidgets: WidgetBundle {
init() {
// main thread
// ...
// set defaultConfiguration.fileURL to a fixed directory in App Group
// ...
let realm: Realm
do {
realm = try Realm()
log.info(RealmDB.self, "opened")
} catch {
// crashed!!!
log.critical(RealmDB.self, "failed to open, error: \(error.localizedDescription)")
fatalError("failed to open realm database, error: \(error.localizedDescription)")
}
// ensure that File Protection is disabled after opening the database
let folderPath = realm.configuration.fileURL!.deletingLastPathComponent().path
try! FileManager.default.setAttributes([FileAttributeKey.protectionKey: FileProtectionType.none],
ofItemAtPath: folderPath)
// ... Should I move the File-Protection-Disable code to the front of The |
The iOS 14 widget extension still crashes with a probability of about a few percent, even though I have set
The |
It seems that this problem occurred after an app upgrade. Not quite sure yet, just guessing. |
@gongzhang are you able to create a reproduction case from the app upgrade discovery? Also 'Should I move the File-Protection-Disable code to the front of try Realm()?', yes you should. |
@leemaguire No, I can't reproduce it in development environment. However, my own device recorded a similar crash a few days ago. From the logs, it appears that the main app was not active when the widget crash occurred. About 20 seconds later, the widget extension started up itself again and everything was fine. And it had no relation to app upgrade. 🤔 |
@gongzhang is this still an issue? If so could you open a new Github issue with the details? Thanks. |
Also having this problem. It's when a user installs an updated version of the app, although this app update has nothing to do with Realm or anything that should need a migration. |
@jln19 Would you be able to open a new issue with the details? Thanks |
I'm experiencing this same crash recently. My previous version of realm was 3.17.3. For me the crash seems to happen if:
|
@BarryDuggan a Realm file created with v10 is not backward compatible with previous versions. |
@gongzhang can you try moving the lines: let folderPath = realm.configuration.fileURL!.deletingLastPathComponent().path
try! FileManager.default.setAttributes([FileAttributeKey.protectionKey: FileProtectionType.none],
ofItemAtPath: folderPath) To be before you open the Realm? If you continue seeing the issue, can you please open another ticket for us to comment on? This seems unrelated to the original issue. For anyone still encountering the initial issue, please upgrade to the latest version of Realm. If you still encounter it, please open a new ticket. There are a number of different issues being reported here that are unrelated, so we are going to close this out. |
is 1) realistic? That means that the user has to lock the phone in exactly the millisecond (?) between storing the encryption key and reading it back if I understand it correctly? |
Getting this exception from realm:
This started in a version of our app 3 months ago. We have done realm schema changes and migrations in many of our releases including the one in which this crash started to show up.
I have gone through https://realm.io/docs/swift/latest/#using-realm-with-background-app-refresh, but found that there is mismatch between Realm's and Apple's documentation, specifically this part:
We do access realm when the app is in background (via background fetches and silent notifications). However, our crash numbers are quite high and it's hard to imagine them all happening due to
NSFileProtectionCompleteUntilFirstUserAuthentication
protection level (i.e. user restarting the device and our app waking up and accessing realm via background fetches or silent notifications before user unlocks).Some other things to note:
Goals
Understand when and why realm would throw this exception when using the default file protection level.
Expected Results
More details logs into why
Operation not permitted.
Actual Results
Stack trace only tells
open() failed: Operation not permitted.
Steps to Reproduce
Don't have repro steps yet
Code Sample
NA
Version of Realm and Tooling
Realm framework version:
3.13.1
Realm Object Server version: NA
Xcode version:
10.1 (10B61)
iOS/OSX version:
12.1.4 (16D57)
Dependency manager + version:
Cocoapods 1.5.3
The text was updated successfully, but these errors were encountered: