🐛 Fix behaviour when page cached & server down

E.g. in Firefox reopen tab while server is down - FF will use a cached
copy and for some reason sockjs won't notice that stuff is down. So now
we have a timeout of 5s for initial connection that takes care of that.
This commit is contained in:
Gina Häußge committed 2020-01-24 16:54:52 +01:00
1 parent cb43197105
commit 8087967683
5 files changed
+32 -4

No files matched your search

@@ -13,6 +13,7 @@
this.options = {
timeouts: [0, 1, 1, 2, 3, 5, 8, 13, 20, 40, 100],
connectTimeout: 5000,
rateSlidingWindowSize: 20
};
@@ -24,6 +25,16 @@
this.rateThrottleFactor = 1;
this.rateBase = 500;
this.rateLastMeasurements = [];
this.connectTimeout = undefined;
this.onMessage("connected", function() {
// Make sure to clear connection timeout on connect
if (self.connectTimeout) {
clearTimeout(self.connectTimeout);
self.connectTimeout = undefined;
}
})
};
OctoPrintSocketClient.prototype.propagateMessage = function(event, data) {
@@ -139,6 +150,13 @@
});
};
if (self.connectTimeout) {
clearTimeout(self.connectTimeout);
}
this.connectTimeout = setTimeout(function() {
self.onConnectTimeout();
}, self.options.connectTimeout);
this.socket = new SockJS(url + "sockjs", undefined, opts);
this.socket.onopen = onOpen;
this.socket.onclose = onClose;
@@ -169,6 +187,7 @@
OctoPrintSocketClient.prototype.onReconnectFailed = function() {};
OctoPrintSocketClient.prototype.onConnected = function() {};
OctoPrintSocketClient.prototype.onDisconnected = function(code) {};
OctoPrintSocketClient.prototype.onConnectTimeout = function() {};
OctoPrintSocketClient.prototype.onRateTooLow = function(measured, minimum) {
this.increaseRate();
+7 -2
View File
@@ -45,7 +45,7 @@ function DataUpdater(allViewModels, connectCallback, disconnectCallback) {
self.connect = function() {
if (self._connectedDeferred) {
self._connectedDeferred.reject();
self._connectedDeferred.reject("reconnect");
}
self._connectedDeferred = $.Deferred();
OctoPrint.socket.connect({debug: !!SOCKJS_DEBUG});
@@ -54,7 +54,7 @@ function DataUpdater(allViewModels, connectCallback, disconnectCallback) {
self.reconnect = function() {
if (self._connectedDeferred) {
self._connectedDeferred.reject();
self._connectedDeferred.reject("reconnect");
}
self._connectedDeferred = $.Deferred();
OctoPrint.socket.reconnect();
@@ -121,6 +121,10 @@ function DataUpdater(allViewModels, connectCallback, disconnectCallback) {
}
};
self._onConnectTimeout = function() {
self._connectedDeferred.reject("timeout");
};
self._onConnectMessage = function(event) {
if (self._initializedDeferred) {
self._initializedDeferred.reject();
@@ -399,6 +403,7 @@ function DataUpdater(allViewModels, connectCallback, disconnectCallback) {
OctoPrint.socket.onDisconnected = self._onDisconnected;
OctoPrint.socket.onReconnectAttempt = self._onReconnectAttempt;
OctoPrint.socket.onReconnectFailed = self._onReconnectFailed;
OctoPrint.socket.onConnectTimeout = self._onConnectTimeout;
OctoPrint.socket.onRateTooHigh = self._onDecreaseRate;
OctoPrint.socket.onRateTooLow = self._onIncreaseRate;
OctoPrint.socket
+4
View File
@@ -808,6 +808,10 @@ $(function() {
// make sure we trigger onServerConnect should we dis- and reconnect to the server
dataUpdater.connectCallback = onServerConnect;
// we are now connected to the server and need to change the loading message - jquery instead of
// binding because no bindings yet
$("#page-container-loading-header").html(gettext("Loading OctoPrint's UI, please wait..."));
// perform passive login first
onServerConnect()
.done(function() {
@@ -52,7 +52,7 @@ $(function() {
// we can't do this with bindings since the bindings are not initialized yet if we need this
$("#page-container-loading-header").text("Loading failed");
$("#page-container-loading-spinner").removeClass("fa-spinner fa-spin").addClass("fa-exclamation-triangle text-error");
$("#page-container-loading-error").html(error + " " + _.sprintf("Please check your <a href='%(browser)s' target='_blank' rel='noopener noreferrer'>browser's error console</a> and <code><a href='%(octoprint)s' target='_blank' rel='noopener noreferrer'>octoprint.log</a></code> for possible reasons.", {browser: "https://faq.octoprint.org/browser-console", octoprint: "https://faq.octoprint.org/logs"})).show();
$("#page-container-loading-error").html(error + " " + _.sprintf("Please check your <a href='%(browser)s' target='_blank' rel='noopener noreferrer'>browser's error console</a> and <code><a href='%(octoprint)s' target='_blank' rel='noopener noreferrer'>octoprint.log</a></code> for possible reasons.Also make sure that the server is actually running by reloading this page.", {browser: "https://faq.octoprint.org/browser-console", octoprint: "https://faq.octoprint.org/logs"})).show();
};
}
+1 -1
View File
@@ -44,7 +44,7 @@
<div class="outer">
<div class="inner">
<div class="content">
<h1 id="page-container-loading-header">{{ _('Loading OctoPrint\'s UI, please wait...') }}</h1>
<h1 id="page-container-loading-header">{{ _('Connecting to OctoPrint\'s server...') }}</h1>
<i id="page-container-loading-spinner" class="fa fa-spinner fa-spin fa-4x"></i>
<p id="page-container-loading-error" style="display: none"></p>
</div>