From 07987144cdf41d1450f401560f08cf66bbda3d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=C2=A0Buczek?= Date: Tue, 5 Jan 2021 10:43:21 +0100 Subject: [PATCH] Fix #3169: Database race condition crash at startup. `DataController` internals were initialized after first DB operations, `Migration.launchMigrations` were called first, on a background thread which can result in race conditions. --- .../Application/Delegates/AppDelegate.swift | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Client/Application/Delegates/AppDelegate.swift b/Client/Application/Delegates/AppDelegate.swift index e241c24f1c8..1e80dfa65f8 100644 --- a/Client/Application/Delegates/AppDelegate.swift +++ b/Client/Application/Delegates/AppDelegate.swift @@ -99,10 +99,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati // Set the Firefox UA for browsing. setUserAgent() + + // An attempt to fix #2185. + // There's an unknown crash related to database creation, which happens when tabs are being restored. + // Our DataControllers uses a mix of static and lazy properties, there is a chance that some + // concurrency problems are occuring. + // This forces the database to initialize the most important lazy properties before doing any other + // database related code. + // Please note that this is called after bookmark and keychain restoration processes. + DataController.shared.lazyInitialization() // Start the keyboard helper to monitor and cache keyboard state. KeyboardHelper.defaultHelper.startObserving() - DynamicFontHelper.defaultHelper.startObserving() MenuHelper.defaultHelper.setItems() @@ -112,21 +120,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati let logDate = Date() // Create a new sync log file on cold app launch. Note that this doesn't roll old logs. Logger.syncLogger.newLogWithDate(logDate) - Logger.browserLogger.newLogWithDate(logDate) let profile = getProfile(application) let profilePrefix = profile.prefs.getBranchPrefix() Migration.launchMigrations(keyPrefix: profilePrefix) - // An attempt to fix #2185. - // There's an unknown crash related to database creation, which happens when tabs are being restored. - // Our DataControllers uses a mix of static and lazy properties, there is a chance that some - // concurrency problems are occuring. - // This forces the database to initialize most important lazy properties before doing any other - // database related code. - // Please note that this is called after bookmark and keychain restoration processes. - DataController.shared.lazyInitialization() setUpWebServer(profile) var imageStore: DiskImageStore?