steelbrain / node-ssh

SSH2 with Promises
MIT License
948 stars 94 forks source link

Timed out while waiting for handshake #424

Closed gajus closed 2 years ago

gajus commented 2 years ago

Constantly getting error:

Error: Timed out while waiting for handshake
  at Timeout._onTimeout (/Users/gajus/Documents/dev/contra/contra-manager/node_modules/ssh2/lib/client.js:1014:23)
  at listOnTimeout (node:internal/timers:557:17)
  at processTimers (node:internal/timers:500:7)

The script is simply:

const ssh = new NodeSSH();

await ssh.connect({
  host,
  privateKey: temporaryKeys.privateKey,
  username: temporaryKeys.username,
});

Is there a configuration I am missing?

steelbrain commented 2 years ago

Have you tried connecting through regular SSH client? The error you're experiencing is a network error, and generally means the destination host is not reachable. If you can connect with the regular ssh client, but failing to be able to, with node-ssh then please let me know!

gajus commented 2 years ago

Firewall rules were modified in our organization without me knowing about it. This is what caused the failures.

Thank you for the response.

However, I still (occasionally) see this error, even when I can connect to SSH. Is there a way to increase the timeout limit?

We can pretty easily add a retry logic for these scenarios though.

steelbrain commented 2 years ago

node-ssh pipes the connection options to ssh2 (https://github.com/mscdex/ssh2#client-methods). I think you can use the readyTimeout option to potentially increase the timeout limit.

Good luck!