Skip to content

Commit

Permalink
Merge pull request #179 from goldenhelix/master
Browse files Browse the repository at this point in the history
Fix handling of SSH network errors
  • Loading branch information
apocas authored Jan 3, 2025
2 parents 5cb5a50 + d4bebd0 commit 1712ff1
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/ssh.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ module.exports = function (opt) {
conn.once('ready', function () {
conn.exec('docker system dial-stdio', function (err, stream) {
if (err) {
handleError(err);
handleError(err , fn);
}

fn(null, stream);

stream.addListener('error', (err) => {
handleError(err);
handleError(err, fn);
});
stream.once('close', () => {
conn.end();
agent.destroy();
});
});
}).on('error', (err) => {
handleError(err);
handleError(err, fn);
})
.connect(opt);
conn.once('end', () => agent.destroy());
Expand All @@ -34,10 +34,14 @@ module.exports = function (opt) {
}
};

function handleError(err) {
function handleError(err, cb) {
conn.end();
agent.destroy();
throw err;
if (cb) {
cb(err);
} else {
throw err;
}
}

return agent;
Expand Down

0 comments on commit 1712ff1

Please sign in to comment.