Fix undetectable race condition in open timeline

This commit is contained in:
Ajay Bura 2022-08-14 15:07:15 +05:30
parent dfc84186a8
commit a28ede2f72

View file

@ -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 */