mscdex / mscdex/ssh2

Early close from the ssh server cause the connection to end without error nor ready event

Open
#928 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
JavaScript
Stars
5.8k
Forks
734
PR merge metrics
No merged PRs in 30d

Description

I used this simple code to establish an ssh connection:

ssh.connect(sshOptions);
await new Promise((resolve, reject) => {
	ssh.on('ready', resolve);
	ssh.on('error', reject);
});

I expect the connection to either be ready or fail with an error.

But, if the server close the connection after the greeting message (server ssh version) due to beeing too busy, then the connection end without any ready nor error event.

This code helped me catch this edge case & make sure my promise resolves:

ssh.connect(sshOptions);
await new Promise((resolve, reject) => {
	const onEarlyEnd = reject.bind(null, new Error('SSH early close / end'));
	ssh.on('ready', () => {
		ssh.off('close', onEarlyEnd);
		ssh.off('end', onEarlyEnd);
		resolve();
	});
	ssh.on('error', reject);
	ssh.on('close', onEarlyEnd);
	ssh.on('end', onEarlyEnd);
});

To prevent this tricky issue from happening to other users, could you make sure a ssh.connect will either result in a ready or an error event?
If an end event occurs before the connection is ready, then an error event should be emitted.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at ssh.connect and trace the ready, error, end, and close event paths during an early server disconnect. Reproduce the greeting-then-close case and add coverage showing that a pre-ready end results in an error; done when every connection attempt emits ready or error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.