From fb360de93edd68af4d386013a27acead0b785676 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO <> Date: Fri, 28 Mar 2025 13:51:28 +1100 Subject: [PATCH] try to prevent race condition on database suspending --- Session/Calls/Call Management/SessionCallManager.swift | 8 +++++--- Session/Meta/AppDelegate.swift | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Session/Calls/Call Management/SessionCallManager.swift b/Session/Calls/Call Management/SessionCallManager.swift index efd1eb13f..8568d7d85 100644 --- a/Session/Calls/Call Management/SessionCallManager.swift +++ b/Session/Calls/Call Management/SessionCallManager.swift @@ -190,9 +190,11 @@ public final class SessionCallManager: NSObject, CallManagerProtocol { if dependencies[singleton: .appContext].isInBackground { // Stop all jobs except for message sending and when completed suspend the database dependencies[singleton: .jobRunner].stopAndClearPendingJobs(exceptForVariant: .messageSend) { [dependencies] _ in - dependencies.mutate(cache: .libSessionNetwork) { $0.suspendNetworkAccess() } - dependencies[singleton: .storage].suspendDatabaseAccess() - Log.flush() + if self.currentCall?.hasEnded != false { + dependencies.mutate(cache: .libSessionNetwork) { $0.suspendNetworkAccess() } + dependencies[singleton: .storage].suspendDatabaseAccess() + Log.flush() + } } } } diff --git a/Session/Meta/AppDelegate.swift b/Session/Meta/AppDelegate.swift index 3bcee7a69..6a774eb7b 100644 --- a/Session/Meta/AppDelegate.swift +++ b/Session/Meta/AppDelegate.swift @@ -361,7 +361,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD Log.info(.backgroundPoller, "Background poll failed due to manual timeout.") cancellable?.cancel() - if dependencies[singleton: .appContext].isInBackground { + if dependencies[singleton: .appContext].isInBackground && !self.hasCallOngoing() { dependencies.mutate(cache: .libSessionNetwork) { $0.suspendNetworkAccess() } dependencies[singleton: .storage].suspendDatabaseAccess() Log.flush() @@ -404,7 +404,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD } // If we are still running in the background then suspend the network & database - if dependencies[singleton: .appContext].isInBackground { + if dependencies[singleton: .appContext].isInBackground && !self.hasCallOngoing() { dependencies.mutate(cache: .libSessionNetwork) { $0.suspendNetworkAccess() } dependencies[singleton: .storage].suspendDatabaseAccess() Log.flush()