From 519981a22c8b572eb4b60b04f149580e40095ee1 Mon Sep 17 00:00:00 2001 From: johnnyman727 Date: Wed, 21 Oct 2015 22:55:31 -0700 Subject: [PATCH] Catches closed connections before an exec is attempted --- lib/lan_connection.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/lan_connection.js b/lib/lan_connection.js index 4dd9600c..dac891cd 100644 --- a/lib/lan_connection.js +++ b/lib/lan_connection.js @@ -37,6 +37,11 @@ LAN.Connection.prototype.exec = function(command) { var self = this; return new Promise(function(resolve, reject) { + // Ensure this connection hasn't been closed + if (self.closed) { + return reject(new Error('Remote SSH connection has already been closed')); + } + // Execute the command if (!Array.isArray(command)) { return reject(new Error('Command to execute must be an array of args.')); @@ -87,6 +92,9 @@ LAN.Connection.prototype.open = function() { // Reject with error resolve(self); }).connect(self.auth); + self.ssh.once('close', function() { + self.closed = true; + }); }); };