From e6f36659954653271495ee2c12cd80469a2ee63a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 10 Dec 2017 20:22:22 -0800 Subject: [PATCH] GUACAMOLE-567: Add UNSTABLE tunnel status. Mark tunnel as UNSTABLE if no data has been received in a reasonable amount of time, but the tunnel is technically still open. --- .../src/main/webapp/modules/Tunnel.js | 75 +++++++++++++++++-- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/guacamole-common-js/src/main/webapp/modules/Tunnel.js b/guacamole-common-js/src/main/webapp/modules/Tunnel.js index 63e27c52b..52bd20ac2 100644 --- a/guacamole-common-js/src/main/webapp/modules/Tunnel.js +++ b/guacamole-common-js/src/main/webapp/modules/Tunnel.js @@ -84,11 +84,22 @@ Guacamole.Tunnel = function() { * The maximum amount of time to wait for data to be received, in * milliseconds. If data is not received within this amount of time, * the tunnel is closed with an error. The default value is 15000. - * + * * @type {Number} */ this.receiveTimeout = 15000; + /** + * The amount of time to wait for data to be received before considering + * the connection to be unstable, in milliseconds. If data is not received + * within this amount of time, the tunnel status is updated to warn that + * the connection appears unresponsive and may close. The default value is + * 1500. + * + * @type {Number} + */ + this.unstableThreshold = 1500; + /** * The UUID uniquely identifying this tunnel. If not yet known, this will * be null. @@ -165,7 +176,15 @@ Guacamole.Tunnel.State = { * * @type {Number} */ - "CLOSED": 2 + "CLOSED": 2, + + /** + * The connection is open, but communication through the tunnel appears to + * be disrupted, and the connection may close as a result. + * + * @type {Number} + */ + "UNSTABLE" : 3 }; @@ -219,6 +238,14 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) { */ var receive_timeout = null; + /** + * The current connection stability timeout ID, if any. + * + * @private + * @type {Number} + */ + var unstableTimeout = null; + /** * Additional headers to be sent in tunnel requests. This dictionary can be * populated with key/value header pairs to pass information such as authentication @@ -253,14 +280,24 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) { */ function reset_timeout() { - // Get rid of old timeout (if any) + // Get rid of old timeouts (if any) window.clearTimeout(receive_timeout); + window.clearTimeout(unstableTimeout); - // Set new timeout + // Clear unstable status + if (tunnel.state === Guacamole.Tunnel.State.UNSTABLE) + tunnel.setState(Guacamole.Tunnel.State.OPEN); + + // Set new timeout for tracking overall connection timeout receive_timeout = window.setTimeout(function () { close_tunnel(new Guacamole.Status(Guacamole.Status.Code.UPSTREAM_TIMEOUT, "Server timeout.")); }, tunnel.receiveTimeout); + // Set new timeout for tracking suspected connection instability + unstableTimeout = window.setTimeout(function() { + tunnel.setState(Guacamole.Tunnel.State.UNSTABLE); + }, tunnel.unstableThreshold); + } /** @@ -274,6 +311,10 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) { */ function close_tunnel(status) { + // Get rid of old timeouts (if any) + window.clearTimeout(receive_timeout); + window.clearTimeout(unstableTimeout); + // Ignore if already closed if (tunnel.state === Guacamole.Tunnel.State.CLOSED) return; @@ -682,6 +723,14 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { */ var receive_timeout = null; + /** + * The current connection stability timeout ID, if any. + * + * @private + * @type {Number} + */ + var unstableTimeout = null; + /** * The WebSocket protocol corresponding to the protocol used for the current * location. @@ -733,14 +782,24 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { */ function reset_timeout() { - // Get rid of old timeout (if any) + // Get rid of old timeouts (if any) window.clearTimeout(receive_timeout); + window.clearTimeout(unstableTimeout); - // Set new timeout + // Clear unstable status + if (tunnel.state === Guacamole.Tunnel.State.UNSTABLE) + tunnel.setState(Guacamole.Tunnel.State.OPEN); + + // Set new timeout for tracking overall connection timeout receive_timeout = window.setTimeout(function () { close_tunnel(new Guacamole.Status(Guacamole.Status.Code.UPSTREAM_TIMEOUT, "Server timeout.")); }, tunnel.receiveTimeout); + // Set new timeout for tracking suspected connection instability + unstableTimeout = window.setTimeout(function() { + tunnel.setState(Guacamole.Tunnel.State.UNSTABLE); + }, tunnel.unstableThreshold); + } /** @@ -754,6 +813,10 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { */ function close_tunnel(status) { + // Get rid of old timeouts (if any) + window.clearTimeout(receive_timeout); + window.clearTimeout(unstableTimeout); + // Ignore if already closed if (tunnel.state === Guacamole.Tunnel.State.CLOSED) return;