diff --git a/src/octoprint/static/js/lib/sockjs.js b/src/octoprint/static/js/lib/sockjs.js index f168d5f7b3..c39fc727e0 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(websocket) { + console.warn("watchdog websocket timeout"); + websocket._close(1006, 'Server lost session'); +} SockJS.prototype._transportMessage = function(msg) { debug('_transportMessage', msg); var self = this @@ -859,6 +863,8 @@ SockJS.prototype._transportMessage = function(msg) { 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 +929,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.