Fix deadlock when drafts persistent container is initialized simultaneously on background and main threads

Fixes #374
This commit is contained in:
Shadowfacts 2023-05-04 18:33:06 -04:00
parent 7b218bfd75
commit 346888db41
1 changed files with 4 additions and 0 deletions

View File

@ -60,6 +60,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
} }
} }
// make sure the persistent container is initialized on the main thread
// otherwise initializing it on the background thread can deadlock with accessing it on the main thread elsewhere
_ = DraftsPersistentContainer.shared
DispatchQueue.global(qos: .userInitiated).async { DispatchQueue.global(qos: .userInitiated).async {
let oldDraftsFile = documentsDirectory.appendingPathComponent("drafts").appendingPathExtension("plist") let oldDraftsFile = documentsDirectory.appendingPathComponent("drafts").appendingPathExtension("plist")
let appGroupDraftsFile = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.space.vaccor.Tusker")!.appendingPathComponent("drafts").appendingPathExtension("plist") let appGroupDraftsFile = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.space.vaccor.Tusker")!.appendingPathComponent("drafts").appendingPathExtension("plist")