From 806e4dbc5dcf04e422824d9bf2c8c3d207c85726 Mon Sep 17 00:00:00 2001 From: Orlando Hohmeier Date: Thu, 22 Mar 2018 16:46:45 +0100 Subject: [PATCH] fix(MesosStateStore): adjust stream data handling Use `Promise.resolve().then()` to trigger the stream subscription asynchronously on the same macrotask (by using a microtask). Events emitted by the strean, trigger `onStreamData` which is used to emit an event (using EventEmitter) called `MESOS_STATE_CHANGE`. This change will mitigate issues in which errors in view components lead to stale data because the error propagation broke the stream. N.B. `EventEmitter` is synchronous meaning that every delay in an event handler effects the `emit` execution time and errors propagate up to the `emit` call which sometimes leads to undesireable behavior. Closes DCOS-21784 --- src/js/stores/MesosStateStore.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/js/stores/MesosStateStore.js b/src/js/stores/MesosStateStore.js index 33dd372c39..ee53e71a29 100644 --- a/src/js/stores/MesosStateStore.js +++ b/src/js/stores/MesosStateStore.js @@ -56,7 +56,7 @@ class MesosStateStore extends GetSetBaseStore { this.on(eventName, callback); if (this.shouldSubscribe()) { - this.subscribe(); + Promise.resolve().then(() => this.subscribe()); } } @@ -99,7 +99,8 @@ class MesosStateStore extends GetSetBaseStore { // refresh limits to the UI. They are: // // MOST once every (Config.getRefreshRate() * 0.5) ms. due to debounceTime. - // LEAST once every tick of Config.getRefreshRate() ms in Observable.interval + // LEAST once every tick of Config.getRefreshRate() ms in + // Observable.interval // // TODO: https://jira.mesosphere.com/browse/DCOS-18277 this.stream = waitStream