mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
Merge pull request #114 from vector-im/bwindels/handle-sync-timeout
Handle sync timeout
This commit is contained in:
commit
255559460e
@ -119,8 +119,13 @@ export class Sync {
|
|||||||
this._status.set(SyncStatus.Syncing);
|
this._status.set(SyncStatus.Syncing);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
// retry same request on timeout
|
||||||
|
if (err.name === "ConnectionError" && err.isTimeout) {
|
||||||
|
// don't run afterSyncCompleted
|
||||||
|
continue;
|
||||||
|
}
|
||||||
this._status.set(SyncStatus.Stopped);
|
this._status.set(SyncStatus.Stopped);
|
||||||
if (!(err instanceof AbortError)) {
|
if (err.name !== AbortError) {
|
||||||
console.warn("stopping sync because of error");
|
console.warn("stopping sync because of error");
|
||||||
console.error(err);
|
console.error(err);
|
||||||
this._error = err;
|
this._error = err;
|
||||||
|
@ -54,6 +54,7 @@ export class RoomEncryption {
|
|||||||
this._notifyMissingMegolmSession = notifyMissingMegolmSession;
|
this._notifyMissingMegolmSession = notifyMissingMegolmSession;
|
||||||
this._clock = clock;
|
this._clock = clock;
|
||||||
this._disposed = false;
|
this._disposed = false;
|
||||||
|
this._isFlushingRoomKeyShares = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async enableSessionBackup(sessionBackup) {
|
async enableSessionBackup(sessionBackup) {
|
||||||
@ -321,25 +322,34 @@ export class RoomEncryption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async flushPendingRoomKeyShares(hsApi, operations = null) {
|
async flushPendingRoomKeyShares(hsApi, operations = null) {
|
||||||
if (!operations) {
|
// this has to be reentrant as it can be called from Room.start while still running
|
||||||
const txn = await this._storage.readTxn([this._storage.storeNames.operations]);
|
if (this._isFlushingRoomKeyShares) {
|
||||||
operations = await txn.operations.getAllByTypeAndScope("share_room_key", this._room.id);
|
return;
|
||||||
}
|
}
|
||||||
for (const operation of operations) {
|
this._isFlushingRoomKeyShares = true;
|
||||||
// just to be sure
|
try {
|
||||||
if (operation.type !== "share_room_key") {
|
if (!operations) {
|
||||||
continue;
|
const txn = await this._storage.readTxn([this._storage.storeNames.operations]);
|
||||||
|
operations = await txn.operations.getAllByTypeAndScope("share_room_key", this._room.id);
|
||||||
}
|
}
|
||||||
const devices = await this._deviceTracker.devicesForRoomMembers(this._room.id, operation.userIds, hsApi);
|
for (const operation of operations) {
|
||||||
await this._sendRoomKey(operation.roomKeyMessage, devices, hsApi);
|
// just to be sure
|
||||||
const removeTxn = await this._storage.readWriteTxn([this._storage.storeNames.operations]);
|
if (operation.type !== "share_room_key") {
|
||||||
try {
|
continue;
|
||||||
removeTxn.operations.remove(operation.id);
|
}
|
||||||
} catch (err) {
|
const devices = await this._deviceTracker.devicesForRoomMembers(this._room.id, operation.userIds, hsApi);
|
||||||
removeTxn.abort();
|
await this._sendRoomKey(operation.roomKeyMessage, devices, hsApi);
|
||||||
throw err;
|
const removeTxn = await this._storage.readWriteTxn([this._storage.storeNames.operations]);
|
||||||
|
try {
|
||||||
|
removeTxn.operations.remove(operation.id);
|
||||||
|
} catch (err) {
|
||||||
|
removeTxn.abort();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
await removeTxn.complete();
|
||||||
}
|
}
|
||||||
await removeTxn.complete();
|
} finally {
|
||||||
|
this._isFlushingRoomKeyShares = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,13 +75,17 @@ export class HomeServerApi {
|
|||||||
method,
|
method,
|
||||||
headers,
|
headers,
|
||||||
body: bodyString,
|
body: bodyString,
|
||||||
timeout: options && options.timeout
|
timeout: options?.timeout
|
||||||
});
|
});
|
||||||
|
|
||||||
const wrapper = new RequestWrapper(method, url, requestResult);
|
const wrapper = new RequestWrapper(method, url, requestResult);
|
||||||
|
|
||||||
if (this._reconnector) {
|
if (this._reconnector) {
|
||||||
wrapper.response().catch(err => {
|
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") {
|
if (err.name === "ConnectionError") {
|
||||||
this._reconnector.onRequestFailed(this);
|
this._reconnector.onRequestFailed(this);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user