Skip to content

Commit

Permalink
Catches closed connections before an exec is attempted
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyman727 committed Oct 22, 2015
1 parent bc9c59f commit 519981a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/lan_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'));
Expand Down Expand Up @@ -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;
});
});
};

Expand Down

0 comments on commit 519981a

Please sign in to comment.