Merge pull request #844 from vector-im/bug/openTimeline-race

Fix undetectable race condition in open timeline
This commit is contained in:
Robert Long 2022-08-14 10:39:01 -07:00 committed by GitHub
commit 4dd42ce164
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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