NodeSSH Reconnect Issue: isConnected() Returns TRUE Even When Connection Unsuccessful
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- node.js, typescript
- Domain
- networking
Research direction
Start at the TypeScript connect method and trace when this.connection is assigned relative to the SSH2 ready, error, end, and close events. Confirm the change by checking that isConnected() does not report a connection after an unsuccessful reconnect; the issue does not name a file or test to run.
Written by the indexing model from the issue text.
Description
I am encountering an issue which seems to be related to ISSUE-429, where the problem still persists. As im not aware of any pitfalls in the code, i have created a suggestion to resolve the issue.
Description:
The problem is caused by the assignment of the this.connection property before the connection promise resolves. Specifically, the this.connection property is being set before the connection.on('ready') event is triggered.
Proposed Solution:
To resolve this issue, I suggest moving the assignment of this.connection inside the connection.on('ready') event in the connect method:
public async connect(givenConfig: Config): Promise<this> {
// ... (Rest of the code remains the same)
const connection = new SSH2.Client();
await new Promise<void>((resolve, reject) => {
connection.on('error', reject);
if (config.onKeyboardInteractive) {
connection.on('keyboard-interactive', config.onKeyboardInteractive);
}
connection.on('ready', () => {
connection.removeListener('error', reject);
this.connection = connection; // Move this line inside the 'ready' event
resolve();
});
connection.on('end', () => {
if (this.connection === connection) {
this.connection = null;
}
});
connection.on('close', () => {
if (this.connection === connection) {
this.connection = null;
}
reject(new SSHError('No response from server', 'ETIMEDOUT'));
});
connection.connect(config);
});
return this;
}
Will i help?
Yeah, let us discuss and i can create a PR :)
- Dominant language
- TypeScript
- Stars
- 1k
- Forks
- 94
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
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.
More from steelbrain/node-ssh
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
steelbrain/node-ssh#487 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
steelbrain/node-ssh#482 · 3 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
steelbrain/node-ssh#474 · 3 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
steelbrain/node-ssh#473 · 1 comment · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 20/100
steelbrain/node-ssh#472 ·
All issues in steelbrain/node-ssh
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
cli: `execCargoMetadata` decodes stdout per chunk, corrupting non-ASCII paths across pipe boundariesOpen
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 62/100
lingdojo/kana-dojo#34127 · 1 comment · 5 reactions ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
osmlab/name-suggestion-index#13104 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100