-
Notifications
You must be signed in to change notification settings - Fork 295
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
ForestDB crashes frequently in the background because of protection data level #1422
Comments
Thanks for reporting this. I don't think we have tested this case. I don't think we have an option to disable / enable auto compaction on ForestDB. |
One workaround that I can think of now is closing the database when the app goes into background and reopen when the app is on the background. However it's also requires some additional code change such as recreating views and replicators. |
Thanks for the suggested workaround, but is a painful one. It would be useful if there was an API to suspend the database instead of completely closing it down, that would be more reasonable. Still though, every internal call in Couchbase should be guarded using the native flag |
Any more thoughts given to this? It's a rather nasty bug for Couchbase Lite, not just ForestDB. Couchbase needs to be more conscious and smarter about running in the background on iOS. Currently, it's a completely ignored, but is a common use case. It's probably crashing just about every app out there that's using the default settings. |
Even if file protection triggers errors, it shouldn't lead to a crash. Looks like this is exposing some bugs in our code — the first crash looks like the result of a missing C++ |
There's no public API for disabling auto-compaction for ForestDB; I think you'd have to modify some code inside CBL to do that. For now I think Pasin's suggestion of closing the database is best. |
This is weird … I'm not sure why the C++ runtime is aborting in |
Figured out the above crash; resolved it as couchbase/cbforest#105. |
That's great news! Is there a way I can try it out? Also out of curiousity, how's the Couchbase team testing for this, because I don't think there's a way to unit test this because the simulator/IDE doesn't have encryption, I've only found that this can be only tested on a real device (unless I'm missing something). Thanks again for following up on this! |
Well, that's the problem: we don't have good tests for this, because it has to be tested manually. That's how it slipped through. |
The fix for couchbaselabs/cbforest#105 has been merged into the master branch. |
* Enabled file protection in the iOS test app (note: only takes effect on a real device; simulator does not implement file protection!) * The test app logs when app state changes in various ways, like going into/out of the background or files becoming inaccessible. * Made MYBackgroundMonitor work better if the app is already backgrounded and if the background task expires. (See MYUtilities commit) * Added CBLDatabase.fileProtection property * REST replicator monitors when files become inaccessible and suspends the replicator for the duration. * Thread-safety improvements in CBLRestReplicator+Backgrounding: make sure UIApplication is only called on the main thread. * Defined new internal status kCBLStatusFilesystemLocked for when we know that file I/O failed due to file protection. It gets reported as a 500 status with message “Device locked”. Should fix #1461 (background monitor); #1443 #1422 #1405 (file protection).
We came from SQLite
storageType
and things seemed to be more under control while we sprinkleUIApplication.sharedApplication().protectedDataAvailable
throughout our app so things don't crash while the protected data is unavailable in the background.Switching to
ForestDB
, things were noticeably fast, but noticing more frequent crashes while in the background. My thought is becauseForestDB
tries to do a lot of unattended maintenance in the background like auto-compaction and other things automatically.However, it never checks to compare the protection data availability with its protection level set on the file, which is
NSFileProtectionCompleteUnlessOpen
by default. This I believe is an oversight by Couchbase Lite for iOS in general, the core code should constantly be checking theprotectedDataAvailable
otherwise Couchbase crashes the app in the background for the majority of test cases.Any ideas how to suspend ForestDB in the background or turn off auto-compaction? Anything else I can do to make Couchbase Lite more robust and conscious of the protect data state while in the background?
Here are some of the crash reports:
The text was updated successfully, but these errors were encountered: