From 87cd6cbed7e15dc0a126c23c5d34a3b90b5f58d0 Mon Sep 17 00:00:00 2001 From: Josef-MrBeam Date: Thu, 15 Sep 2022 09:16:57 +0200 Subject: [PATCH 1/2] add heartbeat watchdog --- src/octoprint/static/js/lib/sockjs.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/octoprint/static/js/lib/sockjs.js b/src/octoprint/static/js/lib/sockjs.js index f168d5f7b3..189ca25c81 100644 --- a/src/octoprint/static/js/lib/sockjs.js +++ b/src/octoprint/static/js/lib/sockjs.js @@ -778,6 +778,7 @@ SockJS.CONNECTING = 0; SockJS.OPEN = 1; SockJS.CLOSING = 2; SockJS.CLOSED = 3; +SockJS.WATCHDOG_WEBSOCKET_TIMEOUT = 30000; // The heartbeat appears every 25 seconds, so we have 5 seconds delay buffer SockJS.prototype._receiveInfo = function(info, rtt) { debug('_receiveInfo', rtt); @@ -842,7 +843,10 @@ SockJS.prototype._transportTimeout = function() { this._transportClose(2007, 'Transport timed out'); } }; - +SockJS.prototype._websocketWatchdogCb = function(weboscket) { + console.warn("watchdog websocket timeout"); + weboscket._close(1006, 'Server lost session'); +} SockJS.prototype._transportMessage = function(msg) { debug('_transportMessage', msg); var self = this @@ -858,7 +862,8 @@ SockJS.prototype._transportMessage = function(msg) { return; case 'h': this.dispatchEvent(new Event('heartbeat')); - debug('heartbeat', this.transport); + clearTimeout(this.heartbeatWatchdog); + this.heartbeatWatchdog = setTimeout(this._websocketWatchdogCb, SockJS.WATCHDOG_WEBSOCKET_TIMEOUT, this); return; } @@ -923,6 +928,7 @@ SockJS.prototype._open = function() { this.transport = this._transport.transportName; this.dispatchEvent(new Event('open')); debug('connected', this.transport); + this.heartbeatWatchdog = setTimeout(this._websocketWatchdogCb, SockJS.WATCHDOG_WEBSOCKET_TIMEOUT, this); } else { // The server might have been restarted, and lost track of our // connection. From fb0745baf915252646a1207ad8d608aa73017e94 Mon Sep 17 00:00:00 2001 From: Josef-MrBeam Date: Thu, 15 Sep 2022 13:52:34 +0200 Subject: [PATCH 2/2] revert debug deleteion fix spelling --- src/octoprint/static/js/lib/sockjs.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/octoprint/static/js/lib/sockjs.js b/src/octoprint/static/js/lib/sockjs.js index 189ca25c81..c39fc727e0 100644 --- a/src/octoprint/static/js/lib/sockjs.js +++ b/src/octoprint/static/js/lib/sockjs.js @@ -843,9 +843,9 @@ SockJS.prototype._transportTimeout = function() { this._transportClose(2007, 'Transport timed out'); } }; -SockJS.prototype._websocketWatchdogCb = function(weboscket) { +SockJS.prototype._websocketWatchdogCb = function(websocket) { console.warn("watchdog websocket timeout"); - weboscket._close(1006, 'Server lost session'); + websocket._close(1006, 'Server lost session'); } SockJS.prototype._transportMessage = function(msg) { debug('_transportMessage', msg); @@ -862,6 +862,7 @@ SockJS.prototype._transportMessage = function(msg) { return; case 'h': this.dispatchEvent(new Event('heartbeat')); + debug('heartbeat', this.transport); clearTimeout(this.heartbeatWatchdog); this.heartbeatWatchdog = setTimeout(this._websocketWatchdogCb, SockJS.WATCHDOG_WEBSOCKET_TIMEOUT, this); return;