realm-swift
realm-swift copied to clipboard
'default.realm.lock': open() failed: Operation not permitted
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
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.
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
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/.
yes thank you we will make feedback here after release of this fix
@MarouMhz just checking in to see if you have any feedback after implementing the above suggestions?
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 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?
@MarouMhz do you have any follow up on our last question?
Closing due to no response from user.
@MarouMhz did you ever find a solution for this?