Merge pull request #114 from vector-im/bwindels/handle-sync-timeout

Handle sync timeout
This commit is contained in:
Bruno Windels 2020-09-25 08:48:26 +00:00 committed by GitHub
commit 255559460e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 18 deletions

View file

@ -119,8 +119,13 @@ export class Sync {
this._status.set(SyncStatus.Syncing);
}
} catch (err) {
// retry same request on timeout
if (err.name === "ConnectionError" && err.isTimeout) {
// don't run afterSyncCompleted
continue;
}
this._status.set(SyncStatus.Stopped);
if (!(err instanceof AbortError)) {
if (err.name !== AbortError) {
console.warn("stopping sync because of error");
console.error(err);
this._error = err;

View file

@ -54,6 +54,7 @@ export class RoomEncryption {
this._notifyMissingMegolmSession = notifyMissingMegolmSession;
this._clock = clock;
this._disposed = false;
this._isFlushingRoomKeyShares = false;
}
async enableSessionBackup(sessionBackup) {
@ -321,6 +322,12 @@ export class RoomEncryption {
}
async flushPendingRoomKeyShares(hsApi, operations = null) {
// this has to be reentrant as it can be called from Room.start while still running
if (this._isFlushingRoomKeyShares) {
return;
}
this._isFlushingRoomKeyShares = true;
try {
if (!operations) {
const txn = await this._storage.readTxn([this._storage.storeNames.operations]);
operations = await txn.operations.getAllByTypeAndScope("share_room_key", this._room.id);
@ -341,6 +348,9 @@ export class RoomEncryption {
}
await removeTxn.complete();
}
} finally {
this._isFlushingRoomKeyShares = false;
}
}
async _sendRoomKey(roomKeyMessage, devices, hsApi) {

View file

@ -75,13 +75,17 @@ export class HomeServerApi {
method,
headers,
body: bodyString,
timeout: options && options.timeout
timeout: options?.timeout
});
const wrapper = new RequestWrapper(method, url, requestResult);
if (this._reconnector) {
wrapper.response().catch(err => {
// Some endpoints such as /sync legitimately time-out
// (which is also reported as a ConnectionError) and will re-attempt,
// but spinning up the reconnector in this case is ok,
// as all code ran on session and sync start should be reentrant
if (err.name === "ConnectionError") {
this._reconnector.onRequestFailed(this);
}