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 when query executed in background #1077

Closed
kronik opened this issue Oct 28, 2014 · 17 comments
Closed

Crash when query executed in background #1077

kronik opened this issue Oct 28, 2014 · 17 comments
Assignees

Comments

@kronik
Copy link

kronik commented Oct 28, 2014

Hi!

My app is crashing almost every time (about 90% cases) when the app (voip) is running in background and later is trying to handle push notification. It executes a query to select all object of particular type. Crash:

Error Domain=io.realm Code=1 "open() failed: Operation not permitted" UserInfo=0x170a62340 {NSLocalizedDescription=open() failed: Operation not permitted, Error Code=1}

iOS8, iPhone5S, Locked with passcode. This issue doesn't happen on iOS7 Locked WITHOUT passcode.

@jpsim
Copy link
Contributor

jpsim commented Oct 28, 2014

This sounds like it might be an NSFileProtection issue, since its default behavior changed in iOS 8. I'll see if I can reproduce it and identify the root cause.

@kronik
Copy link
Author

kronik commented Oct 28, 2014

Just tried to remove passcode from the same iphone5s and reproduce the issue. And it didn't! So you're right it's something related with file protection.

@kronik
Copy link
Author

kronik commented Nov 3, 2014

@jpsim Any plans to fix this issue?

@jpsim
Copy link
Contributor

jpsim commented Nov 3, 2014

I haven't been able to reproduce the issue. For example, this code works fine on my locked iOS 8 device:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert categories:nil]];

    [[RLMRealm defaultRealm] transactionWithBlock:^{
        [DemoObject createInDefaultRealmWithObject:@[@"Hello from Realm!"]];
    }];

    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    localNotif.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
    localNotif.alertBody = @"Hello!";
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    return YES;
}

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
    NSLog(@"Recieved Notification %@",notif);
    NSLog(@"all realm objects: %@", [DemoObject allObjects]);
}

@kronik
Copy link
Author

kronik commented Nov 4, 2014

@jpsim I can't understand why I can't reproduce this issue on a synthetic app/test but it looks like this issue related with memory corruption or leak because I constantly get EXC_BAD_ACCESS in RLMResultsValidateAttached:

crash

@jpsim
Copy link
Contributor

jpsim commented Nov 4, 2014

Is there any chance you could send us your project privately? It would help troubleshoot this issue. help@realm.io.

@jpsim
Copy link
Contributor

jpsim commented Dec 5, 2014

Hi @kronik, were you ever able to reproduce this issue outside your project? Could you try sending us your project privately so we can identify and fix the issue? You can send it to us at help@realm.io.

Thanks!

@jpsim
Copy link
Contributor

jpsim commented Dec 8, 2014

Closing since we were never able to reproduce and have yet to receive sufficient troubleshooting information from @kronik.

@frankcjw
Copy link

frankcjw commented Apr 2, 2015

I have the same issue that realm crash when handle push notification in background ..

@jpsim
Copy link
Contributor

jpsim commented Apr 2, 2015

@frankcjw if your phone is locked when this happens, please refer to my answer in #1260 (comment).

If the phone is unlocked, then that's possibly a bug in Realm and we'd really appreciate a sample Xcode project that we can run to reproduce the issue. Thanks!

@Fab1n
Copy link

Fab1n commented May 13, 2015

I get the same issue. Totally works on simulator, crashes on device

@jpsim
Copy link
Contributor

jpsim commented May 13, 2015

@Fab1n have you tried setting the realm file's parent directory to use NSFileProtectionNone as discussed here: #1874 (comment)?

[[NSFileManager defaultManager] setAttributes:@{NSFileProtectionKey: NSFileProtectionNone} ofItemAtPath:[RLMRealm.defaultRealmPath stringByDeletingLastPathComponent] error:&err];

@Fab1n
Copy link

Fab1n commented May 13, 2015

I found the "bug". My fault, used a file from the bundle with file protection... And then realm cannot alter the file. Should be as expected. Sorry for the inconvenience

@yoshyosh
Copy link
Contributor

is there a way we can have a better error message around this?

@Fab1n
Copy link

Fab1n commented May 15, 2015

OK, still there is an issue. I cannot open the file on device from bundle in readonly mode. The FilePermission exception is not catched but instead the last catch statement (exception ex).
The file is contained in the main bundle 2 folders below the main executable.

@jpsim
Copy link
Contributor

jpsim commented May 22, 2015

@Fab1n could you send us a project that reproduces this issue? You should definitely be able to open a readonly realm file in your app bundle.

@Fab1n
Copy link

Fab1n commented Jun 2, 2015

Sorry for this late answer. I managed to open the realm from the bundles folder in readonly mode. No problem here with Realm!!! It was my own issue!!!

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

No branches or pull requests

6 participants