@@ -893,8 +893,11 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
893
893
// Attempt to stop the background task sync loop cleanly, only if the app not already running
894
894
return
895
895
}
896
- userSession? . clientProxy. stopSync ( completion: completion)
897
- clientProxyObserver = nil
896
+
897
+ MainActor . assumeIsolated {
898
+ userSession? . clientProxy. stopSync ( completion: completion)
899
+ clientProxyObserver = nil
900
+ }
898
901
}
899
902
900
903
private func startSync( ) {
@@ -1036,7 +1039,13 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
1036
1039
// This is important for the app to keep refreshing in the background
1037
1040
scheduleBackgroundAppRefresh ( )
1038
1041
1039
- task. expirationHandler = { [ weak self] in
1042
+ /// We have a lot of crashes stemming here which we previously believed are caused by stopSync not being async
1043
+ /// on the client proxy side (see the comment on that method). We have now realised that will likely not fix anything but
1044
+ /// we also noticed this does not crash on the main thread, even though the whole AppCoordinator is on the Main actor.
1045
+ /// As such, we introduced a MainActor conformance on the expirationHandler but we are also assuming main actor
1046
+ /// isolated in the `stopSync` method above.
1047
+ /// https://sentry.tools.element.io/organizations/element/issues/4477794/
1048
+ task. expirationHandler = { @MainActor [ weak self] in
1040
1049
MXLog . info ( " Background app refresh task is about to expire. " )
1041
1050
1042
1051
self ? . stopSync ( isBackgroundTask: true ) {
0 commit comments