Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #2185: loadPersistentStore crash. (#2186)
Browse files Browse the repository at this point in the history
  • Loading branch information
iccub authored Jan 14, 2020
1 parent 87af4cb commit d2975f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Client/Application/Delegates/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati
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?
Expand Down
5 changes: 5 additions & 0 deletions Data/models/DataController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public class DataController: NSObject {
public static var shared: DataController = DataController()
public static var sharedInMemory: DataController = InMemoryDataController()

/// A possible hacky solution to prevent #2185 crashes.
public func lazyInitialization() {
_ = DataController.shared.container
}

public func storeExists() -> Bool {
return FileManager.default.fileExists(atPath: storeURL.path)
}
Expand Down

0 comments on commit d2975f7

Please # to comment.