Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No response from server #78

Open
flyfishMT opened this issue Jun 3, 2022 · 7 comments
Open

No response from server #78

flyfishMT opened this issue Jun 3, 2022 · 7 comments

Comments

@flyfishMT
Copy link

flyfishMT commented Jun 3, 2022

I consistently get the error

Error: No response from server
at Socket. (/app/node_modules/ssh2-promise/node_modules/ssh2/lib/client.js:764:19)
at Socket.emit (events.js:315:20)
at TCP. (net.js:673:12)

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:

const ssh = new SSH2Promise({
  host: <hostname>,
  username: <username>,
  identity: <path to private key>,
});


module.exports = async (searchText) => {
  const MAX = 100;
  const fileToSearch = <path to file>;
  const cmd = `/bin/grep -wi ${searchText} ${fileToSearch} | tail -n ${MAX} | sort -r`;
  const stdout = await ssh.exec(cmd);
  const results = stdout && stdout.split('\n').filter((i) => i !== '');
  return results;
};

I appreciate any help pointing me in the right direction.

@sanketbajoria
Copy link
Owner

@flyfishMT can you please enable debug log, by passing debug function to SSH configuration. Most probably ssh server is getting disconnected.

@flyfishMT
Copy link
Author

@sanketbajoria thanks I will work on this and report back. It's a little difficult as we are only encountering this error in production

@flyfishMT
Copy link
Author

@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

@sanketbajoria
Copy link
Owner

sanketbajoria commented Jun 9, 2022

@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.

@flyfishMT
Copy link
Author

@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);
   // ...
};

@sanketbajoria
Copy link
Owner

@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.

@flyfishMT
Copy link
Author

flyfishMT commented Aug 29, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants