From 346888db411211bbf79b5d762234ddace7ba74ae Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 4 May 2023 18:33:06 -0400 Subject: [PATCH] Fix deadlock when drafts persistent container is initialized simultaneously on background and main threads Fixes #374 --- Tusker/AppDelegate.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tusker/AppDelegate.swift b/Tusker/AppDelegate.swift index 89545f68..9bd2673b 100644 --- a/Tusker/AppDelegate.swift +++ b/Tusker/AppDelegate.swift @@ -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 { let oldDraftsFile = documentsDirectory.appendingPathComponent("drafts").appendingPathExtension("plist") let appGroupDraftsFile = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.space.vaccor.Tusker")!.appendingPathComponent("drafts").appendingPathExtension("plist")