Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop the sync service constantly attempting to restart on auth error. #1654

Merged
merged 2 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {

setupStateMachine()

roomFlowCoordinator.actions.sink { action in
roomFlowCoordinator.actions.sink { [weak self] action in
guard let self else { return }
switch action {
case .presentedRoom(let roomID):
self.analytics.signpost.beginRoomFlow(roomID)
self.stateMachine.processEvent(.selectRoom(roomID: roomID))
analytics.signpost.beginRoomFlow(roomID)
stateMachine.processEvent(.selectRoom(roomID: roomID))
case .dismissedRoom:
self.stateMachine.processEvent(.deselectRoom)
self.analytics.signpost.endRoomFlow()
stateMachine.processEvent(.deselectRoom)
analytics.signpost.endRoomFlow()
}
}
.store(in: &cancellables)
Expand Down
9 changes: 9 additions & 0 deletions ElementX/Sources/Services/Client/ClientProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class ClientProxy: ClientProxyProtocol {
private var cancellables = Set<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 {
client.setDelegate(delegate: nil)
stopSync()
Expand All @@ -79,6 +84,7 @@ class ClientProxy: ClientProxyProtocol {
backgroundTaskService: backgroundTaskService)

client.setDelegate(delegate: ClientDelegateWrapper { [weak self] isSoftLogout in
self?.hasEncounteredAuthError = true
self?.callbacks.send(.receivedAuthError(isSoftLogout: isSoftLogout))
} tokenRefreshCallback: { [weak self] in
self?.callbacks.send(.updateRestorationToken)
Expand Down Expand Up @@ -125,6 +131,8 @@ class ClientProxy: ClientProxyProtocol {
}

func startSync() {
guard !hasEncounteredAuthError else { return }

MXLog.info("Starting sync")

Task {
Expand Down Expand Up @@ -372,6 +380,7 @@ class ClientProxy: ClientProxyProtocol {
MXLog.error("Failed restarting the sync service with error: \(error)")
}

guard !hasEncounteredAuthError else { return }
pixlwave marked this conversation as resolved.
Show resolved Hide resolved
await self.syncService?.start()
}
}
Expand Down