Skip to content

Commit

Permalink
stop metadata sync thread when user logs out
Browse files Browse the repository at this point in the history
  • Loading branch information
Allie Crevier committed Jan 28, 2020
1 parent c7522fd commit 9afaed8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ def on_authenticate_failure(self, result: Exception) -> None:
error = _('There was a problem signing in. '
'Please verify your credentials and try again.')
self.gui.show_login_error(error=error)
self.api_sync.stop()

def login_offline_mode(self):
"""
Expand Down Expand Up @@ -493,6 +494,7 @@ def logout(self):
self.on_logout_failure)
self.api = None
self.api_job_queue.logout()
self.api_sync.stop()
storage.mark_all_pending_drafts_as_failed(self.session)
self.gui.logout()
self.is_authenticated = False
Expand Down
8 changes: 4 additions & 4 deletions securedrop_client/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(

def start(self, api_client: API) -> None:
'''
Stop metadata syncs.
Start metadata syncs.
'''
self.api_client = api_client

Expand All @@ -54,7 +54,7 @@ def stop(self):
logger.debug('Stopping sync thread')
self.sync_thread.quit()

def sync(self):
def _sync(self):
'''
Create and run a new MetadataSyncJob.
'''
Expand All @@ -68,9 +68,9 @@ def sync(self):

def on_sync_success(self) -> None:
self.sync_success.emit()
QTimer.singleShot(self.TIME_BETWEEN_SYNCS_MS, self.sync)
QTimer.singleShot(self.TIME_BETWEEN_SYNCS_MS, self._sync)

def on_sync_failure(self, result: Exception) -> None:
self.sync_failure.emit(result)
if isinstance(result, RequestTimeoutError):
QTimer.singleShot(self.TIME_BETWEEN_SYNCS_MS, self.sync)
QTimer.singleShot(self.TIME_BETWEEN_SYNCS_MS, self._sync)

0 comments on commit 9afaed8

Please sign in to comment.