Open flyfishMT opened 2 years ago
@flyfishMT can you please enable debug log, by passing debug function to SSH configuration. Most probably ssh server is getting disconnected.
@sanketbajoria thanks I will work on this and report back. It's a little difficult as we are only encountering this error in production
@sanketbajoria I was able to reproduce but don't want to post everything up, any advice on what I'm looking for? The first error I see is on connect:
Outbound: Sending CHANNEL_OPEN (r:13, session)
Socket error: read ECONNRESET
@flyfishMT Can you please explain.. how are you using this library Do we open single ssh connection. And, then, we use this same ssh connection to exec command. (Is there a lot of time gap, in between to exec command.) Or do we open new connection every time, to exec the command.
@sanketbajoria the code in my original post is basically exactly how I'm using, that is a "helper" module, and is used by an express endpoint. So the the SSH2Promise object is declare at the module level, and used in the the exported function.
It looked to me like your exec
function handles the ssh connection for me, I don't explicitly connect anywhere.
const helper = require('../helper');
router.get('/:searchText', async (req, res, next) => {
// ...
const results = await helper(searchText);
// ...
};
@flyfishMT Seems to me ssh connection is dropping. Can you set KeepAliveInterval, so that persistent connection can be established.
const ssh = new SSH2Promise({
host: <hostname>,
username: <username>,
identity: <path to private key>,
keepaliveInterval: 60000,
keepaliveCountMax: 5
});
Or for every request. you can create new ssh connection... exec... and close... But, if the number of request are high... go with above method In the meanwhile i will try to debug if connection get dropped, then it should get established automatically.
Hi @sanketbajoria any luck debugging? I thought I had success with with keepaliveCountMax but it cropped up again. However, I don't remember keepaliveInterval being suggested so I haven't tried that. I also tried to just connect and close every time but am now seeing "Error: No Connection" for a time, and then it will work intermittently. For option 2 of re-creating the connection every time, do you recommend instantiating at the module level as in my first comment, or perhaps re-instantiate every time in the exported function that does the work?
I consistently get the error
The first few times I call a function that uses your library. Eventually it works. I know that this is an error from ssh2, but thought that it might be cause be the usage of ssh2 in ssh2-promise, or how I'm using ssh2-promise?
Psuedo-code:
I appreciate any help pointing me in the right direction.