You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-29 16:43:09 +03:00
Stop syncing when the token is invalid
Fixes https://github.com/vector-im/riot-web/issues/9451
This commit is contained in:
18
src/sync.js
18
src/sync.js
@@ -462,6 +462,16 @@ SyncApi.prototype.sync = function() {
|
|||||||
let savedSyncPromise = Promise.resolve();
|
let savedSyncPromise = Promise.resolve();
|
||||||
let savedSyncToken = null;
|
let savedSyncToken = null;
|
||||||
|
|
||||||
|
async function shouldAbortSync(err) {
|
||||||
|
if (err.errcode === "M_UNKNOWN_TOKEN") {
|
||||||
|
// The logout already happened, we just need to stop.
|
||||||
|
console.warn("Token no longer valid - assuming logout");
|
||||||
|
self.stop();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// We need to do one-off checks before we can begin the /sync loop.
|
// We need to do one-off checks before we can begin the /sync loop.
|
||||||
// These are:
|
// These are:
|
||||||
// 1) We need to get push rules so we can check if events should bing as we get
|
// 1) We need to get push rules so we can check if events should bing as we get
|
||||||
@@ -479,6 +489,7 @@ SyncApi.prototype.sync = function() {
|
|||||||
client.pushRules = result;
|
client.pushRules = result;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Getting push rules failed", err);
|
console.error("Getting push rules failed", err);
|
||||||
|
if (shouldAbortSync(err)) return;
|
||||||
// wait for saved sync to complete before doing anything else,
|
// wait for saved sync to complete before doing anything else,
|
||||||
// otherwise the sync state will end up being incorrect
|
// otherwise the sync state will end up being incorrect
|
||||||
debuglog("Waiting for saved sync before retrying push rules...");
|
debuglog("Waiting for saved sync before retrying push rules...");
|
||||||
@@ -564,6 +575,7 @@ SyncApi.prototype.sync = function() {
|
|||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Getting filter failed", err);
|
console.error("Getting filter failed", err);
|
||||||
|
if (shouldAbortSync(err)) return;
|
||||||
// wait for saved sync to complete before doing anything else,
|
// wait for saved sync to complete before doing anything else,
|
||||||
// otherwise the sync state will end up being incorrect
|
// otherwise the sync state will end up being incorrect
|
||||||
debuglog("Waiting for saved sync before retrying filter...");
|
debuglog("Waiting for saved sync before retrying filter...");
|
||||||
@@ -877,6 +889,12 @@ SyncApi.prototype._onSyncError = function(err, syncOptions) {
|
|||||||
console.error("/sync error %s", err);
|
console.error("/sync error %s", err);
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
||||||
|
if (err.errcode === "M_UNKNOWN_TOKEN") {
|
||||||
|
console.warn("Access token no longer valid - stopping sync");
|
||||||
|
this.stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this._failedSyncCount++;
|
this._failedSyncCount++;
|
||||||
console.log('Number of consecutive failed sync requests:', this._failedSyncCount);
|
console.log('Number of consecutive failed sync requests:', this._failedSyncCount);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user