Skip to content

Commit

Permalink
Shortcircuit sync loop if we've requested to stop syncing (#323)
Browse files Browse the repository at this point in the history
* Shortcircuit sync loop if we've requested to stop syncing

* Update src/MatrixClient.ts

Co-authored-by: Andrew Ferrazzutti <andrewf@element.io>

* Apply suggestions from code review

---------

Co-authored-by: Andrew Ferrazzutti <andrewf@element.io>
Co-authored-by: Travis Ralston <travpc@gmail.com>
  • Loading branch information
3 people committed Oct 26, 2023
1 parent 9422886 commit 8aebc8e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/MatrixClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,12 @@ export class MatrixClient extends EventEmitter {
await Promise.resolve(this.storage.setSyncToken(token));
}
} catch (e) {
// If we've requested to stop syncing, don't bother checking the error.
if (this.stopSyncing) {
LogService.info("MatrixClientLite", "Client stop requested - cancelling sync");
return;
}

LogService.error("MatrixClientLite", "Error handling sync " + extractRequestError(e));
const backoffTime = SYNC_BACKOFF_MIN_MS + Math.random() * (SYNC_BACKOFF_MAX_MS - SYNC_BACKOFF_MIN_MS);
LogService.info("MatrixClientLite", `Backing off for ${backoffTime}ms`);
Expand Down

0 comments on commit 8aebc8e

Please sign in to comment.