From cf5dc03864052980d7e0361c078798003adcaac6 Mon Sep 17 00:00:00 2001 From: Miniontoby <47940064+Miniontoby@users.noreply.github.com> Date: Mon, 19 May 2025 14:25:15 +0200 Subject: [PATCH] Fix problem where ready is called multiple times Fix problem where ready is called multiple times because the listener is not getting removed after its called. This caused some issues whilst running .start multiple times --- lib/ssh.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ssh.js b/lib/ssh.js index dcf1df6..a5fe616 100644 --- a/lib/ssh.js +++ b/lib/ssh.js @@ -192,8 +192,9 @@ SSH.prototype.start = function(options) { self._c.on('error', options.fail); - self._c.on('ready', function() { + function ready() { self._c.removeListener('error', options.fail); + self._c.removeListener('ready', ready); options.success(); if (self._commands.length > 0) { @@ -201,7 +202,8 @@ SSH.prototype.start = function(options) { } else { self._c.end(); } - }); + } + self._c.on('ready', ready); if (self.pass && !self.key) { self._c.connect({ host: self.host, @@ -314,4 +316,4 @@ SSH.prototype.off = function(event, callback) { return this; }; -module.exports = SSH; \ No newline at end of file +module.exports = SSH;