Skip to content
Permalink
Browse files

Solve a race condition that could cause 401 responses and a broken UI

Closes #1364. See ticket for details.
  • Loading branch information...
foosel committed Jun 8, 2016
1 parent 4c34cb8 commit 63cec660ca7fddce7803e64825c6b6b7f569b879
@@ -16,12 +16,16 @@ function DataUpdater(allViewModels) {
self._lastProcessingTimes = [];
self._lastProcessingTimesSize = 20;

self.connect = function() {
self._connectCallback = undefined;

self.connect = function(callback) {
var options = {};
if (SOCKJS_DEBUG) {
options["debug"] = true;
}

self._connectCallback = callback;

self._socket = new SockJS(SOCKJS_URI, undefined, options);
self._socket.onopen = self._onconnect;
self._socket.onclose = self._onclose;
@@ -184,6 +188,13 @@ function DataUpdater(allViewModels) {

self.setThrottle(1);

log.info("Connected to the server");

if (self._connectCallback) {
self._connectCallback();
self._connectCallback = undefined;
}

break;
}
case "history": {
@@ -334,6 +345,4 @@ function DataUpdater(allViewModels) {
}
}
};

self.connect();
}
@@ -276,8 +276,6 @@ $(function() {
}
log.info("... dependency resolution done");

var dataUpdater = new DataUpdater(allViewModels);

//~~ Custom knockout.js bindings

ko.bindingHandlers.popover = {
@@ -517,14 +515,6 @@ $(function() {
// reload overlay
$("#reloadui_overlay_reload").click(function() { location.reload(); });

//~~ Starting up the app

_.each(allViewModels, function(viewModel) {
if (viewModel.hasOwnProperty("onStartup")) {
viewModel.onStartup();
}
});

//~~ view model binding

var bindViewModels = function() {
@@ -614,12 +604,31 @@ $(function() {
}
});
});

log.info("Application startup complete");
};

if (!_.has(viewModelMap, "settingsViewModel")) {
throw new Error("settingsViewModel is missing, can't run UI")
}
viewModelMap["settingsViewModel"].requestData(bindViewModels);

var dataUpdaterConnectCallback = function() {
log.info("Finalizing application startup");

//~~ Starting up the app

_.each(allViewModels, function(viewModel) {
if (viewModel.hasOwnProperty("onStartup")) {
viewModel.onStartup();
}
});

viewModelMap["settingsViewModel"].requestData(bindViewModels);
};

log.info("Initial application setup done, connecting to server...");
var dataUpdater = new DataUpdater(allViewModels);
dataUpdater.connect(dataUpdaterConnectCallback);
}
);

@@ -446,11 +446,7 @@ $(function() {
self._enableDragNDrop(true);
self.requestData();
};

self.onServerReconnect = function(payload) {
self._enableDragNDrop(true);
self.requestData();
};
self.onServerReconnect = self.onServerConnect;

self.onServerDisconnect = function(payload) {
self._enableDragNDrop(false);
@@ -129,13 +129,10 @@ $(function() {
self.allViewModels = allViewModels;
};

self.onDataUpdaterReconnect = function() {
self.requestData();
};

self.onStartupComplete = function() {
self.onServerConnect = function() {
self.requestData();
};
self.onServerReconnect = self.onServerConnect;
}

OCTOPRINT_VIEWMODELS.push([

0 comments on commit 63cec66

Please sign in to comment.
You can’t perform that action at this time.