Stop the sync loop after each background app refresh. (#3481)

This commit is contained in:
Doug
2024-11-04 17:21:54 +00:00
committed by GitHub
parent 8c982a1c8a
commit 5ef8cb7246
2 changed files with 16 additions and 3 deletions

View File

@@ -988,7 +988,8 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
// This is important for the app to keep refreshing in the background
scheduleBackgroundAppRefresh()
task.expirationHandler = {
task.expirationHandler = { [weak self] in
self?.stopSync() // Attempt to stop the sync loop cleanly.
MXLog.info("Background app refresh task expired")
task.setTaskCompleted(success: true)
}
@@ -1007,8 +1008,11 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
.collect(.byTimeOrCount(DispatchQueue.main, .seconds(10), 10))
.sink(receiveValue: { [weak self] _ in
guard let self else { return }
MXLog.info("Background app refresh finished")
// Make sure we stop the sync loop, otherwise the ongoing request is immediately
// handled the next time the app refreshes, which can trigger timeout failures.
stopSync()
backgroundRefreshSyncObserver?.cancel()
task.setTaskCompleted(success: true)