mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Stop the sync service constantly attempting to restart on auth error. (#1654)
Additionally removes a retain cycle that was preventing the client from being released. Remove restartSync - the SDK has changed a lot, we no longer need to stop and start the sync loop.
This commit is contained in:
@@ -73,14 +73,15 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
|
|||||||
|
|
||||||
setupStateMachine()
|
setupStateMachine()
|
||||||
|
|
||||||
roomFlowCoordinator.actions.sink { action in
|
roomFlowCoordinator.actions.sink { [weak self] action in
|
||||||
|
guard let self else { return }
|
||||||
switch action {
|
switch action {
|
||||||
case .presentedRoom(let roomID):
|
case .presentedRoom(let roomID):
|
||||||
self.analytics.signpost.beginRoomFlow(roomID)
|
analytics.signpost.beginRoomFlow(roomID)
|
||||||
self.stateMachine.processEvent(.selectRoom(roomID: roomID))
|
stateMachine.processEvent(.selectRoom(roomID: roomID))
|
||||||
case .dismissedRoom:
|
case .dismissedRoom:
|
||||||
self.stateMachine.processEvent(.deselectRoom)
|
stateMachine.processEvent(.deselectRoom)
|
||||||
self.analytics.signpost.endRoomFlow()
|
analytics.signpost.endRoomFlow()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
|||||||
@@ -54,6 +54,11 @@ class ClientProxy: ClientProxyProtocol {
|
|||||||
private var cancellables = Set<AnyCancellable>()
|
private var cancellables = Set<AnyCancellable>()
|
||||||
private var visibleRoomsListProxyStateObservationToken: AnyCancellable?
|
private var visibleRoomsListProxyStateObservationToken: AnyCancellable?
|
||||||
|
|
||||||
|
/// Will be `true` whilst the app cleans up and forces a logout. Prevents the sync service from restarting
|
||||||
|
/// before the client is released which ends up running in a loop. This is a workaround until the sync service
|
||||||
|
/// can tell us *what* error occurred so we can handle restarts more gracefully.
|
||||||
|
private var hasEncounteredAuthError = false
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
client.setDelegate(delegate: nil)
|
client.setDelegate(delegate: nil)
|
||||||
stopSync()
|
stopSync()
|
||||||
@@ -79,6 +84,7 @@ class ClientProxy: ClientProxyProtocol {
|
|||||||
backgroundTaskService: backgroundTaskService)
|
backgroundTaskService: backgroundTaskService)
|
||||||
|
|
||||||
client.setDelegate(delegate: ClientDelegateWrapper { [weak self] isSoftLogout in
|
client.setDelegate(delegate: ClientDelegateWrapper { [weak self] isSoftLogout in
|
||||||
|
self?.hasEncounteredAuthError = true
|
||||||
self?.callbacks.send(.receivedAuthError(isSoftLogout: isSoftLogout))
|
self?.callbacks.send(.receivedAuthError(isSoftLogout: isSoftLogout))
|
||||||
} tokenRefreshCallback: { [weak self] in
|
} tokenRefreshCallback: { [weak self] in
|
||||||
self?.callbacks.send(.updateRestorationToken)
|
self?.callbacks.send(.updateRestorationToken)
|
||||||
@@ -125,6 +131,11 @@ class ClientProxy: ClientProxyProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func startSync() {
|
func startSync() {
|
||||||
|
guard !hasEncounteredAuthError else {
|
||||||
|
MXLog.warning("Ignoring request, this client has an unknown token.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
MXLog.info("Starting sync")
|
MXLog.info("Starting sync")
|
||||||
|
|
||||||
Task {
|
Task {
|
||||||
@@ -360,21 +371,6 @@ class ClientProxy: ClientProxyProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Private
|
// MARK: Private
|
||||||
|
|
||||||
private func restartSync(delay: Duration = .zero) {
|
|
||||||
Task {
|
|
||||||
try await Task.sleep(for: delay)
|
|
||||||
|
|
||||||
do {
|
|
||||||
MXLog.info("Restarting the sync service.")
|
|
||||||
try await self.syncService?.stop()
|
|
||||||
} catch {
|
|
||||||
MXLog.error("Failed restarting the sync service with error: \(error)")
|
|
||||||
}
|
|
||||||
|
|
||||||
await self.syncService?.start()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func loadUserAvatarURLFromCache() {
|
private func loadUserAvatarURLFromCache() {
|
||||||
loadCachedAvatarURLTask = Task {
|
loadCachedAvatarURLTask = Task {
|
||||||
@@ -442,7 +438,7 @@ class ClientProxy: ClientProxyProtocol {
|
|||||||
case .running, .terminated, .idle:
|
case .running, .terminated, .idle:
|
||||||
break
|
break
|
||||||
case .error:
|
case .error:
|
||||||
restartSync()
|
startSync()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user