From 98ca893f713ed41060df176de6293d86e4d549d9 Mon Sep 17 00:00:00 2001 From: Volkan Ozcelik Date: Fri, 10 Jul 2015 10:00:35 -0700 Subject: [PATCH 1/2] FIX for application restart when srv not reachable Tested on Mac OS X Yosemite, Chrome Version 43.0.2357.132 (64-bit) Steps to reproduce: 1. Run service by `dashing start` 2. View a dashboard 3. kill the service by CTRL + D 4. wait for five minutes. expectation: page should reload what happens: e.currentTarget.readyState is 0 (not initialized) chrome's EventSource API tries to reconnect to a non-existent server over and over again. The page never refreshes. We clear errorTimerId immediately after we get a message event, so that there won't be redundant restarts. On an edge case, the service might reconnect and won't get any messages for a while which might trigger the timer with errorTimerId; and that will cause only one extra refresh only. --- javascripts/dashing.coffee | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index e5875d8c..a1763375 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -96,15 +96,20 @@ source = new EventSource('events') source.addEventListener 'open', (e) -> console.log("Connection opened", e) +errorTimerId = null + source.addEventListener 'error', (e)-> console.log("Connection error", e) - if (e.currentTarget.readyState == EventSource.CLOSED) + UNINITIALIZED = 0 + if (e.currentTarget.readyState == UNINITIALIZED || + e.currentTarget.readyState == EventSource.CLOSED) console.log("Connection closed") - setTimeout (-> + errorTimerId = setTimeout (-> window.location.reload() ), 5*60*1000 source.addEventListener 'message', (e) -> + clearTimeout(errorTimerId) data = JSON.parse(e.data) if lastEvents[data.id]?.updatedAt != data.updatedAt if Dashing.debugMode @@ -123,3 +128,4 @@ source.addEventListener 'dashboards', (e) -> $(document).ready -> Dashing.run() + From 3241bf6970a51446c0c609f7589bf396c50744d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20=C3=96z=C3=A7elik?= Date: Fri, 10 Jul 2015 10:14:56 -0700 Subject: [PATCH 2/2] reset errorTimerId on message event. --- javascripts/dashing.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index a1763375..3958eefa 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -110,6 +110,7 @@ source.addEventListener 'error', (e)-> source.addEventListener 'message', (e) -> clearTimeout(errorTimerId) + errorTimerId = null data = JSON.parse(e.data) if lastEvents[data.id]?.updatedAt != data.updatedAt if Dashing.debugMode