mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 13:37:11 +00:00
Prevent the sync service from looping so tightly on failure (#2540)
Add a delay when restarting the sync service and prevent the service from restarting when stopped.
This commit is contained in:
parent
046f1dd533
commit
da0fcfe052
@ -211,6 +211,27 @@ class ClientProxy: ClientProxyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
/// A stored task for restarting the sync after a failure. This is stored so that we can cancel
|
||||
/// it when `stopSync` is called (e.g. when signing out) to prevent an otherwise infinite
|
||||
/// loop that was triggered by trying to sync a signed out session.
|
||||
@CancellableTask private var restartTask: Task<Void, Never>?
|
||||
|
||||
func restartSync() {
|
||||
guard restartTask == nil else { return }
|
||||
|
||||
restartTask = Task { [weak self] in
|
||||
do {
|
||||
// Until the SDK can tell us the failure, we add a small
|
||||
// delay to avoid generating multi-gigabyte log files.
|
||||
try await Task.sleep(for: .milliseconds(250))
|
||||
self?.startSync()
|
||||
} catch {
|
||||
MXLog.error("Restart cancelled.")
|
||||
}
|
||||
self?.restartTask = nil
|
||||
}
|
||||
}
|
||||
|
||||
func stopSync() {
|
||||
stopSync(completion: nil)
|
||||
}
|
||||
@ -218,6 +239,11 @@ class ClientProxy: ClientProxyProtocol {
|
||||
private func stopSync(completion: (() -> Void)?) {
|
||||
MXLog.info("Stopping sync")
|
||||
|
||||
if restartTask != nil {
|
||||
MXLog.warning("Removing the sync service restart task.")
|
||||
restartTask = nil
|
||||
}
|
||||
|
||||
Task {
|
||||
do {
|
||||
defer {
|
||||
@ -592,7 +618,7 @@ class ClientProxy: ClientProxyProtocol {
|
||||
case .running, .terminated, .idle:
|
||||
break
|
||||
case .error:
|
||||
startSync()
|
||||
restartSync()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user