Reputation: 3294
this.connection = new Connection(); //ssh2 connection
async.waterfall([function(callback) {
// some initialization code to connect
}
}], function(err, opts) {
if (err) {
callback({
message: 'Error during connecting to the device...',
detail: err
}, false);
} else {
console.log('Connecting to ... ' + JSON.stringify(self.info));
self.connection.on('ready', function() {
console.info('Connected... opening a shell...');
callback(null, true);
}).on('error', function(err) {
console.error('Error during connecting to the device: ' + err);
callback({
message: 'Error during connecting to the device...',
detail: err
}, false);
}).on('end', function() {
console.info("Connection ended...");
}).on('close', function(hadError) {
console.info("Connection closed..." + (hadError ? " with error" : ""));
}).connect(opts);
}
});
Referring to the above code, I am connecting to a device using an ssh2 connection, everything works fine..I am getting console logs for on 'ready', on 'close' ,etc but not able to get the console logs when an on 'error' occurs.
I can capture the on 'error'event on win7 32 bit but not on MacOSx(10.9.5) or on Linux(Ubuntu 12). The on 'error' event is triggered when I forcefully end the connection to the device(say plug out the lan cable from my system).
Is this some limitation on Mac/Linux w.r.t the ssh2 module or is it that I am doing something wrong in the way to capture an error.
Any pointers will be really helpful.
node js version v0.10.29 ssh2 version v0.4.8
Upvotes: 2
Views: 1219
Reputation: 3294
Raised the issue in github https://github.com/mscdex/ssh2/issues/364
Solution was to use a keepaliveInterval,it's default value is 0. So played around to keep an optimum value for my application and it worked.
Upvotes: 1