mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
Bring back the background refresh stop sync crash fix, this time with a forced conformance to the main actor.
- follow up to https://github.com/element-hq/element-x-ios/pull/3942 and https://github.com/element-hq/element-x-ios/pull/3946
This commit is contained in:
committed by
Stefan Ceriu
parent
901c833c40
commit
d5f9860898
@@ -895,8 +895,11 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
|||||||
// Attempt to stop the background task sync loop cleanly, only if the app not already running
|
// Attempt to stop the background task sync loop cleanly, only if the app not already running
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userSession?.clientProxy.stopSync(completion: completion)
|
|
||||||
clientProxyObserver = nil
|
MainActor.assumeIsolated {
|
||||||
|
userSession?.clientProxy.stopSync(completion: completion)
|
||||||
|
clientProxyObserver = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func startSync() {
|
private func startSync() {
|
||||||
@@ -1038,12 +1041,20 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
|||||||
// This is important for the app to keep refreshing in the background
|
// This is important for the app to keep refreshing in the background
|
||||||
scheduleBackgroundAppRefresh()
|
scheduleBackgroundAppRefresh()
|
||||||
|
|
||||||
task.expirationHandler = { [weak self] in
|
/// We have a lot of crashes stemming here which we previously believed are caused by stopSync not being async
|
||||||
|
/// on the client proxy side (see the comment on that method). We have now realised that will likely not fix anything but
|
||||||
|
/// we also noticed this does not crash on the main thread, even though the whole AppCoordinator is on the Main actor.
|
||||||
|
/// As such, we introduced a MainActor conformance on the expirationHandler but we are also assuming main actor
|
||||||
|
/// isolated in the `stopSync` method above.
|
||||||
|
/// https://sentry.tools.element.io/organizations/element/issues/4477794/
|
||||||
|
task.expirationHandler = { @Sendable [weak self] in
|
||||||
MXLog.info("Background app refresh task is about to expire.")
|
MXLog.info("Background app refresh task is about to expire.")
|
||||||
|
|
||||||
self?.stopSync(isBackgroundTask: true) {
|
Task { @MainActor in
|
||||||
MXLog.info("Marking Background app refresh task as complete.")
|
self?.stopSync(isBackgroundTask: true) {
|
||||||
task.setTaskCompleted(success: true)
|
MXLog.info("Marking Background app refresh task as complete.")
|
||||||
|
task.setTaskCompleted(success: true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user