question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Timeout while waiting for handshake or handshake errors

See original GitHub issue

Hello,

I was working on a script to fetch some files from an sftp server through a SOCKS5 proxy and I noticed some strange behaviour. I managed to use a workaround to make it work, but I saw that people are experiencing this issue so it might be worth investigating more.

I was getting timeouts (Only when using the proxy though) when calling the sftp.connect(ssh_config) function. So I tried using the ssh2 library directly, and I was able to connect without any issue (through the proxy) My workaround was to connect the ssh2 client from outside the ssh2-sftp-client library and do the same calls as the ssh2-sftp-client library afterwards.

const SSHClient = require('ssh2').Client;
const sftpClient = require("ssh2-sftp-client");

const sftp = new sftpClient();

var ssh_config = {
    host: process.env.ssh_hostname,
    port: process.env.ssh_port,
    username: process.env.ssh_username,
    privateKey: process.env.ssh_key_secret,
    passphrase: process.env.ssh_key_passphrase,
    debug: (txt) => { console.log('[ssh]', txt) },
    sock: socket
};

function getSftpConnection() {
    return new Promise((resolve) => {
        var conn = new SSHClient();
        sftp.client = conn;
        conn.connect(ssh_config);
        conn.on('ready', function () {
            console.log('sftp connection ready !');
            resolve(conn);
        });
    });
}

await getSftpConnection();
await sftp.getSftpChannel();
await sftp.get(
    files_config.remote.inputFilePath,
    files_config.local.inputFilePath
); //Works !

The original solution that is failing is :

const sftpClient = require("ssh2-sftp-client");
const sftp = new sftpClient();

var ssh_config = {
    host: process.env.ssh_hostname,
    port: process.env.ssh_port,
    username: process.env.ssh_username,
    privateKey: process.env.ssh_key_secret,
    passphrase: process.env.ssh_key_passphrase,
    debug: (txt) => { console.log('[ssh]', txt) },
    sock: socket
};

await sftp.connect(ssh_config); //Fails !
await sftp.get(
    files_config.remote.inputFilePath,
    files_config.local.inputFilePath
);

I tried to find the cause but didn’t see anything obvious. Maybe it has something to do with one of the event listeners initialized by the library.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
theophilusxcommented, Jan 31, 2022

New version of ssh2 just released, so pushing out 7.2.2 now. Will take a little time to get to all the npmjs.com servers.

0reactions
theophilusxcommented, Jan 21, 2022

OK. I have been waiting for a new ssh2 version before pushing out the new ssh2-sftp-client version, but I think I will just have to go ahead and push out a new one now and do another one later if necessary once a new ssh2 is released. Bit of a pain as I know there are a couple of issues people are encountering which are fixed in ssh2 master.

I’ll push a new version out on Monday.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Timed out while waiting for handshake · Issue #338 - GitHub
Should also have mentioned, the timed out while waiting for handshake typically means that the client is unable to connect to the remote ......
Read more >
ssh2 timed out while waiting for handshake - node.js
I am trying to use node.js to issue command line in my Linux servers via ssh. I found this https://github.com/mscdex/ssh2 and tried to...
Read more >
DigitalOcean timeout while waiting for handshake - Bobcares
How to resolve DigitalOcean timeout while waiting for handshake? · Firstly, check for ssh misconfigurations. · Check if there is any firewall rule ......
Read more >
Timed out while waiting for handshake - DigitalOcean
I've recently installed the console agent as instructed by digitalocean. However when i tried to use it, it shows error time out while...
Read more >
Copy files over SSH, Error: Timed out while waiting for ...
Copy files over SSH, Error: Timed out while waiting for handshake.. susuraj.r. - Reported Oct 07, 2020. I have provided the right Key...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found