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

Inconsistent "Unable to open a realm at path" exceptions after upgrading to 0.98.6 #3426

Closed
maxneust opened this issue Apr 12, 2016 · 19 comments
Labels

Comments

@maxneust
Copy link

I've updated to 0.98.6, and a few of our users started getting this issue when calling [RLMRealm defaultRealm] on initialization. I've never seen this type of crash before, only on 0.98.6.

Goals

Open the default realm.

Expected Results

Default realm opened and ready to use.

Actual Results

Realm not opened, crash.

Thread : 
Fatal Exception: RLMException
/var/mobile/Containers/Data/Application/0DFD7667-3CA1-433A-9CF3-0DE4E56A6CCA/Documents/default.realm: Unable to open a realm at path '/var/mobile/Containers/Data/Application/0DFD7667-3CA1-433A-9CF3-0DE4E56A6CCA/Documents/default.realm'
0  CoreFoundation                 0x26e5e137 __exceptionPreprocess
1  libobjc.A.dylib                0x352e8c77 objc_exception_throw
2  Polarsteps                     0x2f01c5 RLMSetErrorOrThrow(NSError*, NSError* __autoreleasing*) (RLMUtil.mm:314)
3  Polarsteps                     0x2dfcf1 RLMRealmTranslateException(NSError* __autoreleasing*) (RLMRealm.mm:259)
4  Polarsteps                     0x2e0107 +[RLMRealm openSharedRealm:error:] (RLMRealm.mm:282)
5  Polarsteps                     0x2e045b +[RLMRealm realmWithConfiguration:error:] (RLMRealm.mm:350)
6  Polarsteps                     0x2df399 +[RLMRealm defaultRealm] (RLMRealm.mm:162)
7  Polarsteps                     0xaabc3 -[PolarstepsAppDelegate initRealm] (PolarstepsAppDelegate.m:349)
8  Polarsteps                     0xaab07 -[PolarstepsAppDelegate initAndMaybeCompactRealm] (PolarstepsAppDelegate.m:297)
9  Polarsteps                     0xa8423 -[PolarstepsAppDelegate application:didFinishLaunchingWithOptions:] (PolarstepsAppDelegate.m:69)
10 UIKit                          0x2a529e75 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:]
11 UIKit                          0x2a72042b -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:]
12 UIKit                          0x2a722acf -[UIApplication _runWithMainScene:transitionContext:completion:]
13 UIKit                          0x2a72d7a9 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke
14 UIKit                          0x2a721287 -[UIApplication workspaceDidEndTransaction:]
15 FrontBoardServices             0x2d930ec1 __31-[FBSSerialQueue performAsync:]_block_invoke_2
16 CoreFoundation                 0x26e24255 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__
17 CoreFoundation                 0x26e23519 __CFRunLoopDoBlocks
18 CoreFoundation                 0x26e22073 __CFRunLoopRun
19 CoreFoundation                 0x26d6d9a1 CFRunLoopRunSpecific
20 CoreFoundation                 0x26d6d7b3 CFRunLoopRunInMode
21 UIKit                          0x2a523a57 -[UIApplication _run]
22 UIKit                          0x2a51e635 UIApplicationMain
23 Polarsteps                     0x59da7 main (main.m:16)
24 libdyld.dylib                  0x358b6aaf start

Steps to Reproduce

Can't reproduce it consistently - this only started happening in the latest version of the app, which included a Realm update from 0.96.2 to 0.98.6. It occurs to 1-5% of our users.

Code Sample

This is the initialization code that crashes on the [RLMRealm defaultRealm] call.

    RLMRealmConfiguration *defaultConfiguration = [RLMRealmConfiguration defaultConfiguration];
    defaultConfiguration.schemaVersion = 12;
    defaultConfiguration.migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion) {
        [...]
    };
    [RLMRealmConfiguration setDefaultConfiguration:defaultConfiguration];
    [RLMRealm defaultRealm];

Version of Realm and Tooling

BuildVersion: 15B42

/Applications/Xcode.app/Contents/Developer
Xcode 7.3
Build version 7D175

/Users/maxi/.rvm/gems/ruby-2.2.1/bin/pod
0.39.0
Realm (0.98.6)

/bin/bash
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15)

(not in use here)

/usr/local/bin/git
git version 2.5.0

@maxneust
Copy link
Author

Can anyone help me with this? It's happening to a considerable amount of our users now, and we didn't see this error once on previous versions of Realm. Could this be related with this, where some users that ran into that issue are left with a corrupted realm file?

The error message is very generic so that doesn't help, neither the fact that we can't reproduce it.

If this keeps happening we'll have to move out of Realm.

Thanks.

@bdash
Copy link
Contributor

bdash commented Apr 14, 2016

The generic Unable to open a realm at path '…' message can indicate that the Realm file you're attempting to open is invalid. It can also indicate other things too. I've filed #3438 to track making it clear from the error what the underlying cause is.

Do you have any reason to think that #3422 would be resulting in a corrupted Realm file? If so, we'd appreciate details so we can understand and address that. An exception during a migration block shouldn't be able to corrupt the Realm file.

@maxneust
Copy link
Author

No particular reason to think that #3422 is related, only that crashes from that report were pretty strange and they were happening during the execution of a migration block, so that could have corrupted the Realm file. If that shouldn't happen then nothing else changed on the app side other than migrating from 0.96.2 to 0.98.6.

Do you have any ETA on when #3438 will be available? Anything else I can help with for figuring it out?

Thanks

@bdash
Copy link
Contributor

bdash commented Apr 15, 2016

We have no ETA on #3438 at this time.

Are you able to reproduce this at all yourself? Are you in contact with any users that are able to reproduce this? Being able to retrieve a Realm file that is hitting this issue would provide more information about what's going on here.

@jpsim
Copy link
Contributor

jpsim commented May 3, 2016

Just following up on @bdash's last comment:

Are you able to reproduce this at all yourself? Are you in contact with any users that are able to reproduce this? Being able to retrieve a Realm file that is hitting this issue would provide more information about what's going on here.

@maxneust
Copy link
Author

maxneust commented May 5, 2016

I've been trying to reproduce this myself and couldn't. I waited to respond to this to see if submitting a new version of the app with the latest Realm version would help, but it's been live for a few days now and it didn't.

Unfortunately I couldn't find any users experiencing this that are also geographically close to me yet so no way to get ahold of a problematic Realm file.

I'll keep trying to find a way to reproduce it - any pointers would be appreciated.

@justinWShJ
Copy link

Woo! I also got this crash, and with these Realm files! Any way to fix it?
ProblemRealmFile.zip

@jpsim
Copy link
Contributor

jpsim commented May 11, 2016

@justinWShJ could you please open a new issue with a detailed bug report including exact steps to reproduce? I can open the file you shared fine in the Realm Browser version 0.101.

@jpsim
Copy link
Contributor

jpsim commented May 26, 2016

I'm closing this issue since no one has been able to reproduce similar issues. #3560 was recently merged, which should help diagnose issues relating to accessing files moving forward.

@maxneust
Copy link
Author

I've updated to 1.0.1, error is still present - the traces now include some more detail and are one of the following two variants:

1:

Fatal Exception: RLMException
/var/mobile/Containers/Data/Application/B80217D5-A561-4F3C-B5BF-370A28431253/Documents/default.realm.management/log_access: Unable to open a realm at path '/var/mobile/Containers/Data/Application/B80217D5-A561-4F3C-B5BF-370A28431253/Documents/default.realm.management/log_access'. Please use a path where your app has read-write permissions.

2:

Fatal Exception: RLMException
/var/mobile/Containers/Data/Application/37419249-3CDA-419F-A3B7-1692C5EB1244/Documents/default.realm: Unable to open a realm at path '/var/mobile/Containers/Data/Application/37419249-3CDA-419F-A3B7-1692C5EB1244/Documents/default.realm': Bad Realm file header (#1).

  1. sounds very strange - I'm always using the default config/path. It's the app documents dir so I also don't understand why there could be a write permissions error. What could have caused this?

And for 2) I have no idea what could be causing a bad file header - is there any way to recover from that?

Thanks.

@jpsim jpsim assigned jpsim and unassigned bdash Jun 27, 2016
@jpsim
Copy link
Contributor

jpsim commented Jun 27, 2016

Sorry to hear you're still having trouble with this. I've reopened the issue for you.

  1. sounds very strange - I'm always using the default config/path. It's the app documents dir so I also don't understand why there could be a write permissions error. What could have caused this?

Is it possible this device is jailbroken and the permissions for this location were changed?

And for 2) I have no idea what could be causing a bad file header - is there any way to recover from that?

A bad Realm file header indicates a corrupted file, which can happen if non-Realm APIs were used to touch the file at all. This commonly happens when users attempt to replace, delete or update a Realm file using system file manager APIs while continuing to access the file using Realm APIs.

@maxneust
Copy link
Author

maxneust commented Jun 28, 2016

Thanks for the response and reopening the issue.

Is it possible this device is jailbroken and the permissions for this location were changed?

According to Crashlytics the users having this issue are not jailbroken.

A bad Realm file header indicates a corrupted file, which can happen if non-Realm APIs were used to touch the file at all. This commonly happens when users attempt to replace, delete or update a Realm file using system file manager APIs while continuing to access the file using Realm APIs.

It would be strange that the reason for this is file manipulation, specially considering that this started happening exactly after updating to a newer Realm version.

Maybe this is indeed related with #3422, where users that had that problem are now left with a corrupted file, despite @bdash's intuition that there's no relation. I would try to reproduce it but besides being intricate, chances of being able to actually reproduce it are slim - I'd need to somehow create a realm file pre-0.96.2 for an older schema version, then 'update' to 0.96.2 and to the latest schema version, run the migration and hope for #3422 to appear, then update to a newer realm version, create a release build, run the app, and hope for the bad header issue to appear.

If there's suspicion from you guys that there could be a link between these two I can try - otherwise, any other suggestion? Last resort I will just recreate the file when this exception happens, but I'd like to avoid that, anything not synchronized to our servers at that point will be lost.

@jpsim
Copy link
Contributor

jpsim commented Jul 6, 2016

I'm sorry for the lack of response, @maxneust, I haven't had anything very useful to write back. If you do manage to reproduce this and share how we can too, I'll gladly investigate this further.

Would it be possible to send us one of the affected Realm files so we can see what went wrong? We might be able to retrieve some data from it.

@borzh
Copy link

borzh commented Jul 22, 2016

I have this issue now. Next code in 1.0.2 version of Realm:

    RLMRealm *db = [RLMRealm defaultRealm];
    [db beginWriteTransaction];
    {
        [db deleteObjects:[Resource allObjects]];
    }
    [db commitWriteTransaction];

Sometimes I get next error:

*** Terminating app due to uncaught exception 'RLMException', reason: 'open("/Users/noone/Library/Developer/CoreSimulator/Devices/7AC57A35-577A-40DC-9F85-5D81CE985B68/data/Containers/Data/Application/991905B6-D056-4E59-BEAC-10B3158A3271/Documents/default.realm.management/log_a") failed: No such file or directory'

Sometimes I get next one:
/Users/asdasd/Library/Developer/CoreSimulator/Devices/7AC57A35-577A-40DC-9F85-5D81CE985B68/data/Containers/Data/Application/EDE88B82-3856-4EBB-B56F-17309312D938/Documents/default.realm.management/access_control.write.mx: Directory at path '/Users/asdasd/Library/Developer/CoreSimulator/Devices/7AC57A35-577A-40DC-9F85-5D81CE985B68/data/Containers/Data/Application/EDE88B82-3856-4EBB-B56F-17309312D938/Documents/default.realm.management/access_control.write.mx' does not exist.

@mrackwitz
Copy link
Contributor

@borzh: Is this issue reproducible for you on your own device?
Are you making anywhere modifications to the Realm on the file system as e.g. deleting the database? This is not supported as long as a Realm file is opened and accessed.

@borzh
Copy link

borzh commented Jul 25, 2016

My bad, I am working on a project with a team and I didn't realized that meanwhile in one thread Realm was reading/saving database, in the other thread the Realm database was being deleted (via normal file deletion, lol).
So, you are right, it was an error from our side, sorry.

@jpsim
Copy link
Contributor

jpsim commented Jul 26, 2016

Thanks for following up @borzh. I'll be closing this again for lack of any new information.

@jpsim jpsim closed this as completed Jul 26, 2016
@kmvkrish
Copy link

I am facing the same issue when using realm-java alongside realm-js for a React Native app.
When realm file is created from realm-js, and to access the realm file from native side (Android), i am facing the issue and the app also crashes.

When the app is re-opened, I am able to access the realm file from native code.

Don't know what exactly the reason behind the issue. The crash just logs the below error:
Unable to open realm file at path '': Invalid realm file path provided.

@ilkerbagci
Copy link

I had the same issue and tried too many ways to fix it.
The easiest way to fix this problem is manually creation of the folder XCode cannot reach '/Users/…/Library/Developer/CoreSimulator/Devices/…/data/Containers/Data/Application/…/Documents/...' as explained at https://docs.realm.io/sync/using-synced-realms/errors#unable-to-open-realm-at-path-less-than-path-greater-than-make_dir-failed-no-such-file-or-directory

Once you created this folder and run the project, XCode creates the Realm files inside this folder automatically.

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

No branches or pull requests

9 participants