Merge pull request #1788 from matrix-org/luke/fix-flair-store-potential-mem-leak

Potentially fix a memory leak in FlairStore
This commit is contained in:
David Baker 2018-03-06 12:22:14 +00:00 committed by GitHub
commit d167dbcf86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -154,19 +154,29 @@ class FlairStore extends EventEmitter {
return this._groupProfiles[groupId];
}
// No request yet, start one
if (!this._groupProfilesPromise[groupId]) {
this._groupProfilesPromise[groupId] = matrixClient.getGroupProfile(groupId);
// A request is ongoing, wait for it to complete and return the group profile.
if (this._groupProfilesPromise[groupId]) {
try {
await this._groupProfilesPromise[groupId];
} catch (e) {
// Don't log the error; this is done below
return null;
}
return this._groupProfiles[groupId];
}
// No request yet, start one
console.log('FlairStore: Request group profile of ' + groupId);
this._groupProfilesPromise[groupId] = matrixClient.getGroupProfile(groupId);
let profile;
try {
profile = await this._groupProfilesPromise[groupId];
} catch (e) {
console.log('Failed to get group profile for ' + groupId, e);
console.log('FlairStore: Failed to get group profile for ' + groupId, e);
// Don't retry, but allow a retry when the profile is next requested
delete this._groupProfilesPromise[groupId];
return;
return null;
}
this._groupProfiles[groupId] = {
@ -179,6 +189,7 @@ class FlairStore extends EventEmitter {
/// XXX: This is verging on recreating a third "Flux"-looking Store. We really
/// should replace FlairStore with a Flux store and some async actions.
console.log('FlairStore: Emit updateGroupProfile for ' + groupId);
this.emit('updateGroupProfile');
setTimeout(() => {