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

tvOS 14.3: When Realm is stored in a shared app group container the app is terminated by tvOS #7053

Open
mskrischke opened this issue Jan 18, 2021 · 5 comments

Comments

@mskrischke
Copy link

mskrischke commented Jan 18, 2021

Goals

The app should not be terminated because of open file locks. This seems to be the same problem as in #6671. On tvOS the same issue however seems to still exist.

Expected Results

When the app enters background it stays suspended and is not terminated by runningboardd

Actual Results

runningboardd detects open file locks in a directory where file locks are not allowed and therefore terminates the app.

Steps for others to Reproduce

Instantiate Realm in a shared container for the application group as described in https://realm.io/docs/swift/latest/#tvos.

Code Sample

If I create the database in the default directory for tvOS there is no crash when the app enters background. Only when I create the database in the shared container for the application group the app gets terminated when entering background.

From the console log:

error	14:52:53.889425+0100	runningboardd	[application<de.myapp>:2403] locked files not in allowed directories: /var/mobile/Containers/Data/Application/0XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX6004/tmp
/var/mobile/Containers/Data/Application/0XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX6004
default	14:52:53.889723+0100	runningboardd	[application<de.myapp>:2403] Terminating with context: <RBSTerminateContext| domain:15 code:0xDEAD10CC explanation:[application<de.myapp>:2403] was suspended with locked system files:
/var/mobile/Containers/Shared/AppGroup/8XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX595D/Library/Caches/cache.dev/epg.realm.lock
/var/mobile/Containers/Shared/AppGroup/8XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX595D/Library/Caches/cache.dev/recordings.realm.lock
not in allowed directories:
/var/mobile/Containers/Data/Application/0XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX6004/tmp
/var/mobile/Containers/Data/Application/0XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX6004 reportType:CrashLog maxTerminationResistance:Interactive>
default	14:52:53.889914+0100	runningboardd	[application<de.myapp>:2403] terminate_with_reason() success

I created a minimal sample project that reproduces the issue:
tvos_crash_sample.zip

And here the corresponding log from the Apple TV:
log_sample_crash.txt

Version of Realm and Tooling

Realm framework version: 10.5.1

Realm Object Server version: -

Xcode version: 12.3

iOS/OSX version: tvOS 14.3

Dependency manager + version: Cocoapods 1.10.1

Device: Crash seems to only happen on real devices, reproducable on Apple TV 4K and Apple TV 4th Gen.

@pavel-ship-it
Copy link
Contributor

Hi @mskrischke ,
Could you please confirm is it appear on a real device or in a simulator too?

@mskrischke
Copy link
Author

mskrischke commented Jan 18, 2021

Hi @pavel-ship-it,
I just tried and it seems the crash only happens on a real device and not on a simulator. I tried with a 4th Gen Apple TV 32gb and an Apple TV 4k 32gb. If you need more logs or if you want me to try different versions of Realm please let me know.

@tgoyne
Copy link
Member

tgoyne commented Jan 19, 2021

We unfortunately can't really support sharing a Realm between processes on tvOS. On other platforms, we use named pipes for inter-process synchronization, but tvOS does not support named pipes. Each of the options we do have available to us on tvOS have various problems.

One option is to wrap all of your uses of Realm in NSFileCoordinator, which works very awkwardly with our API as you can't hold onto any objects outside of the callback blocks.

@mskrischke
Copy link
Author

Oh, that's unfortunate. I guess this changed with tvOS 14? In my current setup I have the Realm files in an app group container so I can access them from a Topshelf extension. The extension however only needs read access and doesn't store or manipulate anything in the database.

The obvious workaround would be to move the realm files back into the app's Cache folder and find another way to transmit the necessary data to the extension. I was wondering however if there maybe is some Realm specific configuration that would support my current setup and that I am missing? Like read-only access from the extension and automatic removal of locks when the main app is suspended for example.

@mskrischke
Copy link
Author

In any case I think the documentation under https://realm.io/docs/swift/latest/#tvos should be updated and state clearly that sharing between app and extension is not supported anymore under tvOS 14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants