Created attachment 8818891 [details] IMG_3751.JPG STR: 1. Launch Firefox 2. Sign into a FxA account with history/bookmarks 3. Open the HistoryPanel 4. Quickly background/foreground the app a couple of times 5. Navigate between the home panels Expected: All data should still appear (Top Sites/Bookmarks/History) Actual: Views are all blank and all the data is missing ----- As a result of force closing the database on app background and reopening it on foreground, there seems to be a race condition where a DB close will happen after it tries to reopen causing our connection to the database to be nil which results in no data. I've attached a (crummy) drawing I made to help explain what is probably happening. Essentially since we kick off a sync within a long running background task ID, if we open the app while this occurs before the sync finishes, the reopen command we schedule on the sharedConnectionQueue will be slotted behind the sync end's forceClose call.
Note: The diagram shows that the sync completion block occurs on the main thread which currently is not true. Even if we were to move this invocation to the main thread it wouldn't solve the issue.
So we actually already have code that checks to make sure that we only call shutdown if the application is in the foreground  . What appears to be happening is that we can run into the situation where the app becomes foregrounded then immediately after the upon block from the background sync is scheduled on the main thread on a cycle after reopen has already happened. Since we're enqueuing the shutdown on the main thread, we need to be mindful of it potentially being called after appDidForeground - which makes the foreground check invalid.  https://github.com/mozilla-mobile/firefox-ios/blob/master/Client/Application/AppDelegate.swift#L409
Assignee: nobody → sleroux
Created attachment 8818926 [details] Link to Github pull-request: https://github.com/mozilla-mobile/firefox-ios/pull/2282#attch-to-bugzilla
Attachment #8818926 - Flags: review?(bnicholson)
Comment on attachment 8818926 [details] Link to Github pull-request: https://github.com/mozilla-mobile/firefox-ios/pull/2282#attch-to-bugzilla Makes sense to me.
Attachment #8818926 - Flags: review?(bnicholson) → review+
Status: ASSIGNED → RESOLVED
Last Resolved: 2 years ago
Resolution: --- → FIXED
Whiteboard: [MobileCore] → [MobileCore][needsuplift]
Whiteboard: [MobileCore][needsuplift] → [MobileCore]
You need to log in before you can comment on or make changes to this bug.