From a28ede2f72c88f63d13979f8ec90b93b321dcdf3 Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Sun, 14 Aug 2022 15:07:15 +0530 Subject: [PATCH] Fix undetectable race condition in open timeline --- src/matrix/room/BaseRoom.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/matrix/room/BaseRoom.js b/src/matrix/room/BaseRoom.js index 21b8e93d..09e74d39 100644 --- a/src/matrix/room/BaseRoom.js +++ b/src/matrix/room/BaseRoom.js @@ -47,6 +47,7 @@ export class BaseRoom extends EventEmitter { this._fragmentIdComparer = new FragmentIdComparer([]); this._emitCollectionChange = emitCollectionChange; this._timeline = null; + this._openTimelinePromise = null; this._user = user; this._changedMembersDuringSync = null; this._memberList = null; @@ -542,7 +543,8 @@ export class BaseRoom extends EventEmitter { /** @public */ openTimeline(log = null) { - return this._platform.logger.wrapOrRun(log, "open timeline", async log => { + if (this._openTimelinePromise) return this._openTimelinePromise; + this._openTimelinePromise = this._platform.logger.wrapOrRun(log, "open timeline", async log => { log.set("id", this.id); if (this._timeline) { throw new Error("not dealing with load race here for now"); @@ -554,6 +556,7 @@ export class BaseRoom extends EventEmitter { pendingEvents: this._getPendingEvents(), closeCallback: () => { this._timeline = null; + this._openTimelinePromise = null; if (this._roomEncryption) { this._roomEncryption.notifyTimelineClosed(); } @@ -575,6 +578,7 @@ export class BaseRoom extends EventEmitter { } return this._timeline; }); + return this._openTimelinePromise; } /* allow subclasses to provide an observable list with pending events when opening the timeline */