From c425d7f02f3a0ff1db8bb394d643c56352f8c020 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 9 Mar 2020 15:24:55 +0000 Subject: [PATCH] Make Mjolnir stop more robust Since Mjolnir is a shared instance, we need to be a bit more careful about clearing internal state than we do for components. This clears watcher and dispatcher refs in case `stop` is called multiple times (which can happen in prod as well as tests). --- src/mjolnir/Mjolnir.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mjolnir/Mjolnir.js b/src/mjolnir/Mjolnir.js index 0c99306278..5836ffd57a 100644 --- a/src/mjolnir/Mjolnir.js +++ b/src/mjolnir/Mjolnir.js @@ -65,14 +65,14 @@ export class Mjolnir { } stop() { - SettingsStore.unwatchSetting(this._mjolnirWatchRef); + if (this._mjolnirWatchRef) { + SettingsStore.unwatchSetting(this._mjolnirWatchRef); + this._mjolnirWatchRef = null; + } - try { - if (this._dispatcherRef) dis.unregister(this._dispatcherRef); - } catch (e) { - console.error(e); - // Only the tests cause problems with this particular block of code. We should - // never be here in production. + if (this._dispatcherRef) { + dis.unregister(this._dispatcherRef); + this._dispatcherRef = null; } if (!MatrixClientPeg.get()) return;