From d1c7a792b8cbe34cf4bc77f842e2038615fffe0c Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Sun, 14 Aug 2022 17:43:24 +0530 Subject: [PATCH] Await in fill method to prevent multiple errors --- .../session/room/timeline/tiles/GapTile.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/domain/session/room/timeline/tiles/GapTile.js b/src/domain/session/room/timeline/tiles/GapTile.js index 9bebb7b5..65a01988 100644 --- a/src/domain/session/room/timeline/tiles/GapTile.js +++ b/src/domain/session/room/timeline/tiles/GapTile.js @@ -39,6 +39,17 @@ export class GapTile extends SimpleTile { console.error(`room.fillGap(): ${err.message}:\n${err.stack}`); this._error = err; this.emitChange("error"); + if (err instanceof ConnectionError) { + /* + We need to wait for reconnection here rather than in + notifyVisible() because when we return/throw here + this._loading is set to false and other queued invocations of + this method will succeed and attempt further room.fillGap() calls - + resulting in multiple error entries in logs and elsewhere! + */ + await this._waitForReconnection(); + return true; + } // rethrow so caller of this method // knows not to keep calling this for now throw err; @@ -63,8 +74,8 @@ export class GapTile extends SimpleTile { } catch (e) { if (e instanceof ConnectionError) { - await this.options.client.reconnector.connectionStatus.waitFor(status => status === ConnectionStatus.Online).promise; - canFillMore = true; + // Don't increase depth because this gap fill was a noop + continue; } } depth = depth + 1; @@ -101,6 +112,10 @@ export class GapTile extends SimpleTile { } } + async _waitForReconnection() { + this.options.client.reconnector.connectionStatus.waitFor(status => status === ConnectionStatus.Online).promise; + } + get shape() { return "gap"; }