From 20607dfab0cd86442a53353dd4680ab0639a11aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 31 Aug 2016 15:50:33 +0200 Subject: [PATCH] Work around a race condition(?) causing issues on startup See lengthy comment inside main.js added in this commit. --- src/octoprint/static/js/app/main.js | 15 ++++++++++++++- .../static/js/app/viewmodels/settings.js | 6 +++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/octoprint/static/js/app/main.js b/src/octoprint/static/js/app/main.js index d21cdd5f..0d116502 100644 --- a/src/octoprint/static/js/app/main.js +++ b/src/octoprint/static/js/app/main.js @@ -558,7 +558,20 @@ $(function() { callViewModels(allViewModels, "onStartup"); viewModelMap["settingsViewModel"].requestData() - .done(bindViewModels); + .done(function() { + // There appears to be an odd race condition either in JQuery's AJAX implementation or + // the browser's implementation of XHR, causing a second GET request from inside the + // completion handler of the very same request to never get its completion handler called + // if ETag headers are present on the response (the status code of the request does NOT + // seem to matter here, only that the ETag header is present). + // + // Minimal example with which I was able to reproduce this behaviour can be found + // at https://gist.github.com/foosel/b2ddb9ebd71b0b63a749444651bfce3f + // + // Decoupling all consecutive calls from this done event handler hence is an easy way + // to avoid this problem. A zero timeout should do the trick nicely. + window.setTimeout(bindViewModels, 0); + }); }); } ); diff --git a/src/octoprint/static/js/app/viewmodels/settings.js b/src/octoprint/static/js/app/viewmodels/settings.js index 3a91f120..a1be680a 100644 --- a/src/octoprint/static/js/app/viewmodels/settings.js +++ b/src/octoprint/static/js/app/viewmodels/settings.js @@ -460,6 +460,9 @@ $(function() { // perform the request self.receiving(true); return OctoPrint.settings.get() + .always(function() { + self.receiving(false); + }) .done(function(response) { self.fromResponse(response, local); @@ -483,9 +486,6 @@ $(function() { deferred.reject(args); }); self.outstanding = []; - }) - .always(function() { - self.receiving(false); }); };