realm-swift icon indicating copy to clipboard operation
realm-swift copied to clipboard

'default.realm.lock': open() failed: Operation not permitted

Open MarouMhz opened this issue 3 years ago • 4 comments
trafficstars

How frequently does the bug occur?

Sometimes

Description

We have tracked in our Crashlytics that some users (approximately 300 users) failed to create Realm file with this error 'default.realm.lock': open() failed: Operation not permitted

We have tried to fix this according to this solution, we have set protection at none to the folder that contain default.realm and default.realm.lock before opening realm

Stacktrace & log output

Unable to open a realm at path '<path_to_Documents>/default.realm.lock': open() failed: Operation not permitted Path: <path_to_Documents>/default.realm.lock Exception backtrace: 0 Realm 0x000000010760b3e4 _ZN5realm4util4File13open_internalERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS1_10AccessModeENS1_10CreateModeEiPb + 712 1 Realm 0x00000001074bf620 _ZN5realm2DB4openERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEbNS_9DBOptionsE + 988 2 Realm 0x00000001074c2968 _ZN5realm2DB4openERNS_11ReplicationERKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEENS_9DBOptionsE + 124 3 Realm 0x00000001074c7134 _ZN5realm2DB6createE

Can you reproduce the bug?

Not yet

Reproduction Steps

This crash is found on the Firebase console, we can't reproduce it. According to the Firebase, it happens more than 300 times and affects more than 200 users. we tried many solutions like this but we still have this issue: https://github.com/realm/realm-swift/issues/7874#issuecomment-1177339671

Version

Realm 10.28.2 and earlier

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

iOS15

Build environment

Xcode version: XCode 13.4 Dependency manager and version: cocoapods 1.11.3

MarouMhz avatar Sep 05 '22 15:09 MarouMhz

Could you share the block you use to set the file protections? I know you linked @dianaafanador3 's Obj-c example from 7874, but in case your using swift or changed it up.

I'm wondering if you're hitting something like this. Create a custom sub-directory, if you're not already, and set those protections. Setting the protections for the app's default Documents might not stick.

ejm01 avatar Sep 06 '22 16:09 ejm01

Thanks for your reply. It's this we tried to set those protections to default Documents. So we will create a custom sub-directory and check if this solve this issue in release version.

If we will do this we should move all realm files to this sub-directory, you know if there is other file/directory related to realm to move ? default.realm.lock default.realm default.realm.management

MarouMhz avatar Sep 07 '22 09:09 MarouMhz

Yes should be those three. Keep in mind that some of these files might get created and deleted by realm system processes, so you can't just apply the protections to the file. Do it to the whole sub-directory. Like mentioned in the earlier link, I think the sub-directory has to be created by you, and not the Documents/.

ejm01 avatar Sep 07 '22 16:09 ejm01

yes thank you we will make feedback here after release of this fix

MarouMhz avatar Sep 07 '22 16:09 MarouMhz

@MarouMhz just checking in to see if you have any feedback after implementing the above suggestions?

leemaguire avatar Sep 26 '22 10:09 leemaguire

We always have crashes reported on Crashlytics even by moving the realm files to Library/Application Support/Realm/

...../Library/Application Support/Realm/default.realm.lock': open() failed: Operation not permitted

MarouMhz avatar Feb 06 '23 16:02 MarouMhz

@MarouMhz this is not a valid iOS directory. Can you show us where you are setting the Realm path and tell us why you need to be setting it to a custom path?

jsflax avatar Feb 07 '23 16:02 jsflax

@MarouMhz do you have any follow up on our last question?

leemaguire avatar Feb 14 '23 14:02 leemaguire

Closing due to no response from user.

leemaguire avatar Mar 29 '23 12:03 leemaguire

@MarouMhz did you ever find a solution for this?

jmtiimo avatar Feb 12 '24 12:02 jmtiimo