-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Keeping file locks for database in shared app group after write violates Apple's recommendation and causes the system kill the app with 0xdead10cc #8017
Comments
I have noticed there are many issues trying to solve the crash when Realm is used in app group container, many of them closed. If Realm doesn't plan to address this, I think that swift-realm should have a huge warning that it is unsuitable to use in app group containers (= any instances where data sharing between app and extension, or multiple apps of a same vendor is needed), as since iOS 14 everyone using Realm for such case will run into this, and this issue seems to be unfixable by user with a current design of Realm. |
On iOS (and watchOS) we do not hold a file lock the entire time the Realm file is open. We acquire one when opening the file, but release it before the initializer returns. Write transactions also hold a lock for the duration of the write, but release it once the write is complete. Opening a Realm, reading and/or writing to it, and then closing it within the span of a single Your extension transitioning to the background while inside a write transaction or while in the middle of opening a Realm will result in the OS killing the process, so if you are not using |
Any updates on this issue or workarounds to resolve it? We are seeing similar behaviour in our application. |
As I wrote above, we believe that what we are doing is valid provided that you are making proper use of the OS APIs for background tasks, and we do not hold file locks outside of write transactions. There isn't really generic advice we can give beyond what I wrote above and that you need to be sure to use the applicable background task APIs. Anything more specific would be very app-specific and require a lot more information about what exactly you're doing and what isn't working. |
How frequently does the bug occur?
All the time
Description
Here is the investigation: #5904 (comment) plus the previous posts in thread.
TLDR: Current design, where file locks are kept even outside write transactions, violates iOS rules when used for a database inside a shared app group (which is the only way to share data between app and its extensions, like WidgetKit, and is a major use case for Realm on iOS). When Realm database is opened in an extension process, Realm keeps the database and auxiliary files locked, and system kills the app extension with
0xdead10cc
as a cause.Here is a more info from Apple arguing why the design, which leaves locked files in the shared app group, is bad: https://developer.apple.com/forums/thread/655225?answerId=632433022#632433022 (linked from #7466 (comment))
The library's vendor is Realm, and it is clearly leaving locked files after finished writes, which causes iOS to kill the app. So I am raising this as an issue.
This was written two years ago (Change in iOS 14 Beta 3 to trigger 0xdead10cc - https://developer.apple.com/forums/thread/655225?answerId=628197022#628197022)
If Realm has communicated clearly that it doesn't support sharing data with the extensions (which it doesn't with the current design), I would have chosen a different solution (either SQLite or Core Data).
Related issues:
#6861 #5904 #6671
Stacktrace & log output
Can you reproduce the bug?
Yes, always
Reproduction Steps
Use Realm in App extension (eg. WidgetKit extension).
Version
10.32.2
What SDK flavour are you using?
Local Database only
Are you using encryption?
No, not using encryption
Platform OS and version(s)
iOS 16.1
Build environment
Xcode version: 14.1
Dependency manager and version: SPM - realm-swift = 10.32.2, realm-core = 12.11.0
The text was updated successfully, but these errors were encountered: