-
Notifications
You must be signed in to change notification settings - Fork 298
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
Hang on iOS7 when app goes to the background #164
Comments
Ugh. Yes, this definitely seems like a similar situation to couchbaselabs/TouchDB-iOS#216, in which an NSCache is releasing content objects, one of which turns around and releases/deallocs the cache itself, causing a deadlock. In this case, a CBLDocument is being released from a cache and dealloced, which causes its CBLDatabase to lose its last reference and be dealloced, which causes the CBLDatabase's cache to be dealloced. |
You should be able to work around this by keeping a reference to one of the objects that gets dealloced in the above scenario. The only database I can think of that wouldn't have any references to it is the If you can get this to reproduce while hooked up to Xcode, it would be very interesting to find out the identities of the CBLDocument and CBLDatabase appearing in the backtrace (frames 17 and 15). |
Created pull request (bug #165) to try to fix this, by postponing releasing of the |
@snej You're right that we don't do anything explicitly with the _replicator database. When a replication is active, that is to say that when we create and start a replication, we hold a reference to it until it is explicitly stopped by us, which is to say that we no longer need that database to be replicated. And when the app goes to the background, we are not explicitly stopping our replications. So, I am confident that references to CBLReplication's are not being dropped in this case. One other note: When handling applicationDidEnterBackground, we do a flush of any changes to our data model, forcing a putProperties on the corresponding CBLDocument(s). I think I mentioned in the past that we don't use CBLModel. But that is all we do when our app goes to the background. Not sure if that could be causing an issue. Once I'm able to repro, I'll try to determine which document and database are hanging. |
@xcvista
|
Modified my pull request zeroing out the _cache variable. Try again please. |
@xcvista @snej I can give you the long version, if you want it. But figured I'd start there. You should be able to repro this now. |
Thanks, that helped. There's some stuff that's not getting torn down properly when a CBLDatabase is deleted, and so it stays around in memory until the app's cache-purging breaks some link cycles. If I fix that, this situation won't occur so you won't hang. Working on it right now. |
Just to follow up, Jens' fix indeed fixed this issue. -Todd |
We recently noticed an app backgrounding hang in our app, and the culprit appears to be CBL. I'm still gathering info from our QE and other developers who have done some more digging, but I wanted to share what I currently know, in the interest of getting the conversation started.
Some background info… We're primarily an iPad only app at the moment. We've committed to supporting iOS7 only in our initial release (submitting to Apple next month!). We support multiple CBL databases open at the same time, each with a replication to a Cloudant server. Our replications are continuous, bi-directional, and NON-persistent.
If we have a database open, and an active replication going on that database, hitting the home button on the iPad, and then switching back to our app, it will be hung in the main thread. Pausing the debugger yields the following backtrace:
Note that CBLDatabase dealloc is called.
Our QE believes this issue occurs only on iOS7. It's not convenient for me to verify this wasn't a problem in iOS6, as all my devices are on iOS7 now.
I believe the issue started between July 30 and August 22. Note that during that time, most of our team was still using iOS6, so we would not have noticed this issue when it was first introduced. The most likely suspect commit was (submitted August 15):
89ec01d
I did some digging, and these GitHub issues were previously resolved, but seemed related:
#120
#96
And this one from TouchDB:
https://github.com/couchbaselabs/TouchDB-iOS/issues/216
Please let me know if you need more info.
Thanks,
-Todd
The text was updated successfully, but these errors were encountered: