don't run afterSyncCompleted and next sync request in parallel
as the otk count the next sync request reports will be outdated if afterSyncCompleted uploaded OTKs, and the next afterSyncCompleted , having the wrong server OTK count, will again upload OTKs. This will overwrite existing OTK keys which will throw BAD_MESSAGE_KEY_ID when creating new sessions with those OTKs
This commit is contained in:
parent
a86b25736c
commit
4dfbd3f3cd
1 changed files with 3 additions and 7 deletions
|
@ -93,14 +93,13 @@ export class Sync {
|
||||||
}
|
}
|
||||||
|
|
||||||
async _syncLoop(syncToken) {
|
async _syncLoop(syncToken) {
|
||||||
let afterSyncCompletedPromise = Promise.resolve();
|
|
||||||
// if syncToken is falsy, it will first do an initial sync ...
|
// if syncToken is falsy, it will first do an initial sync ...
|
||||||
while(this._status.get() !== SyncStatus.Stopped) {
|
while(this._status.get() !== SyncStatus.Stopped) {
|
||||||
let roomStates;
|
let roomStates;
|
||||||
try {
|
try {
|
||||||
console.log(`starting sync request with since ${syncToken} ...`);
|
console.log(`starting sync request with since ${syncToken} ...`);
|
||||||
const timeout = syncToken ? INCREMENTAL_TIMEOUT : undefined;
|
const timeout = syncToken ? INCREMENTAL_TIMEOUT : undefined;
|
||||||
const syncResult = await this._syncRequest(syncToken, timeout, afterSyncCompletedPromise);
|
const syncResult = await this._syncRequest(syncToken, timeout);
|
||||||
syncToken = syncResult.syncToken;
|
syncToken = syncResult.syncToken;
|
||||||
roomStates = syncResult.roomStates;
|
roomStates = syncResult.roomStates;
|
||||||
this._status.set(SyncStatus.Syncing);
|
this._status.set(SyncStatus.Syncing);
|
||||||
|
@ -113,7 +112,7 @@ export class Sync {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this._status.get() !== SyncStatus.Stopped) {
|
if (this._status.get() !== SyncStatus.Stopped) {
|
||||||
afterSyncCompletedPromise = this._runAfterSyncCompleted(roomStates);
|
await this._runAfterSyncCompleted(roomStates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,7 +143,7 @@ export class Sync {
|
||||||
await Promise.all(roomsPromises.concat(sessionPromise));
|
await Promise.all(roomsPromises.concat(sessionPromise));
|
||||||
}
|
}
|
||||||
|
|
||||||
async _syncRequest(syncToken, timeout, prevAfterSyncCompletedPromise) {
|
async _syncRequest(syncToken, timeout) {
|
||||||
let {syncFilterId} = this._session;
|
let {syncFilterId} = this._session;
|
||||||
if (typeof syncFilterId !== "string") {
|
if (typeof syncFilterId !== "string") {
|
||||||
this._currentRequest = this._hsApi.createFilter(this._session.user.id, {room: {state: {lazy_load_members: true}}});
|
this._currentRequest = this._hsApi.createFilter(this._session.user.id, {room: {state: {lazy_load_members: true}}});
|
||||||
|
@ -153,9 +152,6 @@ export class Sync {
|
||||||
const totalRequestTimeout = timeout + (80 * 1000); // same as riot-web, don't get stuck on wedged long requests
|
const totalRequestTimeout = timeout + (80 * 1000); // same as riot-web, don't get stuck on wedged long requests
|
||||||
this._currentRequest = this._hsApi.sync(syncToken, syncFilterId, timeout, {timeout: totalRequestTimeout});
|
this._currentRequest = this._hsApi.sync(syncToken, syncFilterId, timeout, {timeout: totalRequestTimeout});
|
||||||
const response = await this._currentRequest.response();
|
const response = await this._currentRequest.response();
|
||||||
// wait here for the afterSyncCompleted step of the previous sync to complete
|
|
||||||
// before we continue processing this sync response
|
|
||||||
await prevAfterSyncCompletedPromise;
|
|
||||||
|
|
||||||
const isInitialSync = !syncToken;
|
const isInitialSync = !syncToken;
|
||||||
syncToken = response.next_batch;
|
syncToken = response.next_batch;
|
||||||
|
|
Reference in a new issue