From 8ba80426e33f8c1cb715d8a0a7c55170dbbf6ec4 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sat, 2 Feb 2019 10:20:22 -0700 Subject: [PATCH] Better disconnect - should resolve issues with SSH --- core/client.js | 7 ++++++- core/servers/login/ssh.js | 8 ++++++-- core/servers/login/telnet.js | 9 +++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/core/client.js b/core/client.js index 894119bf..d340981b 100644 --- a/core/client.js +++ b/core/client.js @@ -511,7 +511,12 @@ Client.prototype.end = function () { // // We can end up calling 'end' before TTY/etc. is established, e.g. with SSH // - return this.output.end.apply(this.output, arguments); + if(_.isFunction(this.disconnect)) { + return this.disconnect(); + } else { + // legacy fallback + return this.output.end.apply(this.output, arguments); + } } catch(e) { // ie TypeError } diff --git a/core/servers/login/ssh.js b/core/servers/login/ssh.js index d13acf4b..ee63ac78 100644 --- a/core/servers/login/ssh.js +++ b/core/servers/login/ssh.js @@ -278,13 +278,17 @@ function SSHClient(clientConn) { }); }); - clientConn.on('end', () => { - self.emit('end'); // remove client connection/tracking + clientConn.once('end', () => { + return self.emit('end'); // remove client connection/tracking }); clientConn.on('error', err => { self.log.warn( { error : err.message, code : err.code }, 'SSH connection error'); }); + + this.disconnect = function() { + return clientConn.end(); + }; } util.inherits(SSHClient, baseClient.Client); diff --git a/core/servers/login/telnet.js b/core/servers/login/telnet.js index 29d766ba..fb6ca745 100644 --- a/core/servers/login/telnet.js +++ b/core/servers/login/telnet.js @@ -550,6 +550,15 @@ function TelnetClient(input, output) { this.emit('ready', { firstMenu : Config().loginServers.telnet.firstMenu } ); } }; + + this.disconnect = function() { + try { + return this.output.end.apply(this.output, arguments); + } + catch(e) { + // nothing + } + }; } util.inherits(TelnetClient, baseClient.Client);