🐛 Make sockjs connection timeout configurable

Used to default to 5s, now set by default to 10s, can be completely
disabled by settings devel.sockJsConnectTimeout to 0.

Might be a possible solution for #3502.
This commit is contained in:
Gina Häußge committed 2020-04-07 11:58:32 +02:00
1 parent 3fccee1bc2
commit ebe2c53de7
5 files changed
+32 -9

No files matched your search

+18 -5
View File
@@ -199,6 +199,12 @@ def index():
enable_gcodeviewer = settings().getBoolean(["gcodeViewer", "enabled"])
enable_timelapse = settings().getBoolean(["webcam", "timelapseEnabled"])
enable_loading_animation = settings().getBoolean(["devel", "showLoadingAnimation"])
enable_sd_support = settings().get(["feature", "sdSupport"])
enable_webcam = settings().getBoolean(["webcam", "webcamEnabled"]) and bool(settings().get(["webcam", "stream"]))
enable_temperature_graph = settings().get(["feature", "temperatureGraph"])
gcode_mobile_threshold = settings().get(["gcodeViewer", "mobileSizeThreshold"])
gcode_threshold = settings().get(["gcodeViewer", "sizeThreshold"])
sockjs_connect_timeout = settings().getInt(["devel", "sockJsConnectTimeout"])
def default_template_filter(template_type, template_key):
if template_type == "navbar":
@@ -217,6 +223,12 @@ def index():
enable_gcodeviewer,
enable_timelapse,
enable_loading_animation,
enable_sd_support,
enable_webcam,
enable_temperature_graph,
gcode_mobile_threshold,
gcode_threshold,
sockjs_connect_timeout,
wizard_active(_templates.get(locale))] + sorted(["{}:{}".format(to_unicode(k, errors="replace"),
to_unicode(v, errors="replace"))
for k, v in _plugin_vars.items()])
@@ -372,14 +384,15 @@ def index():
_plugin_vars,
now)
render_kwargs.update(dict(
enableWebcam=settings().getBoolean(["webcam", "webcamEnabled"]) and bool(settings().get(["webcam", "stream"])),
enableTemperatureGraph=settings().get(["feature", "temperatureGraph"]),
enableWebcam=enable_webcam,
enableTemperatureGraph=enable_temperature_graph,
enableAccessControl=enable_accesscontrol,
accessControlActive=accesscontrol_active,
enableLoadingAnimation=enable_loading_animation,
enableSdSupport=settings().get(["feature", "sdSupport"]),
gcodeMobileThreshold=settings().get(["gcodeViewer", "mobileSizeThreshold"]),
gcodeThreshold=settings().get(["gcodeViewer", "sizeThreshold"]),
enableSdSupport=enable_sd_support,
gcodeMobileThreshold=gcode_mobile_threshold,
gcodeThreshold=gcode_threshold,
sockJsConnectTimeout=sockjs_connect_timeout * 1000,
wizard=wizard,
now=now,
))
+1
View File
@@ -414,6 +414,7 @@ default_settings = {
},
"useFrozenDictForPrinterState": True,
"showLoadingAnimation": True,
"sockJsConnectTimeout": 10,
"virtualPrinter": {
"enabled": False,
"okAfterResend": False,
+11 -3
View File
@@ -120,6 +120,12 @@
url += "/";
}
var timeout = self.options.connectTimeout;
if (opts.hasOwnProperty("connectTimeout")) {
timeout = opts.connectTimeout;
delete opts.connectTimeout;
}
var onOpen = function() {
self.reconnecting = false;
self.reconnectTrial = 0;
@@ -155,9 +161,11 @@
if (self.connectTimeout) {
clearTimeout(self.connectTimeout);
}
self.connectTimeout = setTimeout(function() {
self.onConnectTimeout();
}, self.options.connectTimeout);
if (timeout > 0) {
self.connectTimeout = setTimeout(function() {
self.onConnectTimeout();
}, timeout);
}
self.socket = new SockJS(url + "sockjs", undefined, opts);
self.socket.onopen = onOpen;
+1 -1
View File
@@ -48,7 +48,7 @@ function DataUpdater(allViewModels, connectCallback, disconnectCallback) {
self._connectedDeferred.reject("reconnect");
}
self._connectedDeferred = $.Deferred();
OctoPrint.socket.connect({debug: !!SOCKJS_DEBUG});
OctoPrint.socket.connect({debug: !!SOCKJS_DEBUG, connectTimeout: SOCKJS_CONNECT_TIMEOUT});
return self._connectedDeferred.promise();
};
@@ -24,6 +24,7 @@
var SOCKJS_URI = "{{ url_for('index') }}" + "sockjs";
var SOCKJS_DEBUG = CONFIG_DEBUG;
var SOCKJS_CONNECT_TIMEOUT = {{ sockJsConnectTimeout }};
// sockjs should define CLOSE_NORMAL for us, but they don't (from ws spec)
var SOCKJS_CLOSE_NORMAL = 1000;