SSH2 connection failed in production - Timed out while waiting for handshake
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 5.8k
- Forks
- 734
- PR merge metrics
- No merged PRs in 30d
Description
I have the following function in my service to connect to my server using ssh:
async executeSSHCommand(command: string): Promise<string> {
const conn = new Client();
const host = this._configService.get('bbb.host', { infer: true });
const privateKey = this._configService.get('bbb.privateKey', { infer: true });
const passphrase = this._configService.get('bbb.passphrase', { infer: true })?.replace(/\\n/g, '\n');
// console.log('Connecting with:', {
// host,
// user: 'root',
// hasKey: privateKey,
// passphrase: passphrase,
// });
return new Promise((resolve, reject) => {
conn.once('ready', () => {
conn.exec(command, (err, stream) => {
if (err) return reject(err);
let output = '';
stream.on('data', (data) => (output += data.toString()));
stream.on('close', (code) => {
conn.end(); // kończymy połączenie dopiero po zakończeniu komendy
if (code !== 0) return reject(`Command failed with code: ${code}`);
resolve(output);
});
});
});
conn.on('error', (err) => reject(err));
conn.connect({ host, port: 22, username: 'root', privateKey, passphrase });
});
}
Unfortunately, while it works fine in development, it does not work in production (digital ocean app) - I have an error:
Timed out while waiting for handshake
Any ideas how to fix that?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the conn.connect entry point in the reported function and review the ssh2 connection and handshake behavior. Compare the host, port, key, passphrase, and network conditions between development and the DigitalOcean production environment. Done means identifying a reproducible cause for the production-only handshake timeout or confirming that it is external to ssh2.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100