From b245ec70383b7fe3badfe4a587ff751e118c360e Mon Sep 17 00:00:00 2001 From: Samuel Mannehed Date: Tue, 12 Dec 2017 18:25:20 +0100 Subject: [PATCH] Fix disconnect crash when screen doesn't exist The function removeChild throws an exception when the element specified doesn't exist. This can happen when opening the websocket throws an exception during connect. Fixes issue #979 --- core/rfb.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/rfb.js b/core/rfb.js index 63c6c6ba..8f9a5469 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -433,7 +433,16 @@ RFB.prototype = { this._mouse.ungrab(); this._sock.close(); this._print_stats(); - this._target.removeChild(this._screen); + try { + this._target.removeChild(this._screen); + } catch (e) { + if (e.name === 'NotFoundError') { + // Some cases where the initial connection fails + // can disconnect before the _screen is created + } else { + throw e; + } + } clearTimeout(this._resizeTimeout); Log.Debug("<< RFB.disconnect"); },